Can anyone provide some guidance with those 2 issues I'm having? (number generated is out of my range, and number generated always increasing)
Can anyone provide some guidance with those 2 issues I'm having? (number generated is out of my range, and number generated always increasing)
Maybe this might work ...
A random number is always a word variable.
The value is always between 1-65535.
So if the 1-65535 is considered the Decimal part, then multiplying it times the range you want (in your case 20) and take the High Word result, then add the minimum...
Code:Value VAR WORD RND VAR WORD MinCnt CON 10 MaxCnt CON 30 Scale CON MaxCnt - MinCnt RND = 1234 ; The Seed, however you get it RANDOM RND Value = (RND ** Scale) + MinCnt
DT
Base on Darrel code, this line >>> Scale CON MaxCnt - MinCnt << should be Scale CON MaxCnt - MinCnt +1, so the maximum range will be reached.
Thanks Darrel.
I also attached a little file making a set of 6 random numbers range from 10 to 30 based on Darrel code.
Last edited by KVLV; - 25th November 2007 at 11:31. Reason: commented out some code
Someone's paying attention!
Yup you're right KVLV.
+ 1
Why do I always forget that part?
Thanks for the example too.
<br>
DT
Bookmarks