Re: Converting from atom to sequence & Vica Versa
- Posted by Derek Parnell <dparnell at BIGPOND.NET.AU> Nov 04, 2000
- 387 views
Hi Tony, > The third number must be between the NullFrom and the NullTo fields. I assume by this mean that the fields NullFrom and NullTo are expected to contain integers. And that you what a random number in this range. I'll also guess that these values are inclusive values. Given these assumptions, try someting like this (my code is indented, also use integer rather than object whenever you can - its faster) ... -- code generated by Win32Lib IDE v0.9 include Win32Lib.ew without warning ---------------------------------------------------------------------------- ---- -- Window SafeWindow global constant SafeWindow = create( Window, "Random Safe Codes", 0, 90, 148, 680, 696, 0 ) global constant OneNumber = create( EditText, "", SafeWindow, 48, 68, 36, 20, 0 ) global constant TwoNumber = create( EditText, "", SafeWindow, 108, 68, 36, 20, 0 ) global constant ThreeNumber = create( EditText, "", SafeWindow, 164, 68, 36, 20, 0 ) global constant CreateButton = create( PushButton, "Create Code", SafeWindow, 80, 104, 90, 30, 0 ) global constant LText6 = create( LText, "Last Wheel Null Zone", SafeWindow, 32, 184, 116, 20, 0 ) global constant NullFrom = create( EditText, "", SafeWindow, 172, 184, 40, 20, 0 ) global constant NullTo = create( EditText, "", SafeWindow, 224, 184, 40, 20, 0 ) ---------------------------------------------------------------------------- ---- procedure CreateButton_onClick () integer temp, temp2, temp3 -- I've chosen to do the third number first because we must -- check for faulty user input data. temp = floor(getNumber(NullFrom)) if temp < 1 then return end if temp2 = floor(getNumber(NullTo)) if temp2 < 1 then return end if -- Make sure the two numbers are the right way round. if temp > temp2 then temp3 = temp2 temp2 = temp temp = temp3 end if -- Calculate the difference plus one -- Its this value we need to randomize. -- eg. (100 - 90) + 1 ==> 11 temp3 = temp2 - temp + 1 -- Add the random # to the lowest user value -- subtract one to bring it back into range. --eg. 90 + rand(11) - 1 ==> gives a number from 90 to 100, inclusive. temp = temp + rand(temp3) - 1 setText(ThreeNumber,sprintf("%d", temp)) temp = rand(99) setText(OneNumber,sprintf("%d", temp)) temp = rand(99) setText(TwoNumber,sprintf("%d", temp)) end procedure onClick[CreateButton] = routine_id("CreateButton_onClick") WinMain( SafeWindow, Normal ) ------ Derek Parnell Melbourne, Australia (Vote [1] The Cheshire Cat for Internet Mascot)