I need a totally random number from 0 to 10 or from 0 to 100 as a value "NUM" done in QBasic for a random draw program. I currently have this:
RANDOMIZE TIMER: A = INT((RND * 100)): B = INT((RND * 10)): C = (A + B)
NUM = INT(C - (RND * 10))
This is basically just a pile of random mathematical operations to get a random number from 1 to 100.
The problem is i get the same or very similar numbers quite too often. Is there a more reliable way to do this?
The code that you provide does not at all meet the requirement of a "random number from 0 to 10 or from 0 to 100". You start out setting A
to a random number from 0 to 99 and B
to a random number from 0 to 9. But the rest of your calculation does not perform an "OR".
How about this:
RANDOMIZE TIMER
A = INT(RND * 101) // random number from 0 to 100
B = INT(RND * 11) // random number from 0 to 10
C = INT(RND * 2) // random number from 0 to 1
IF C = 0 THEN
NUM = A
ELSE
NUM = B
END IF
or more simplified:
RANDOMIZE TIMER
NUM = INT(RND * 101)
IF INT(RND * 2) = 0 THEN
NUM = INT(RND * 11)
END IF