Second Random variable

kranenborg

Senior Member
Yes, just use the RANDOM command twice using the same variable:, something like this:
Code:
SYMBOL firstRND = w1
SYMBOL secondRND = W2

DO
    RANDOM W0
    firstRND = W0
    RANDOM W0
    SecondRND = W0
LOOP
Since the RANDOM command places the result in the same register as where it takes the "seed" from, you can run it several times, each time a new number is generated
/Jurjen
 
Last edited:

AllyCat

Senior Member
Hi,

It depends how "different" you want the two "random" numbers to be ! Each time you use the command, all it does is to double the value of the seed and then "randomly" adds either 0 or 1. If the seed had a value of >32767 then the overflow when doubling is lost, so the result will effectively have 32768 subtracted from the previous process.

If you want the two random numbers in the loop not to be related, then start with two different seed values (and never zero) and use the different values in the loop, for example:
Code:
w1 = 12345
w2 = 54321
do
   random w1
   random w2
   sertxd (cr,lf,#w1,"  ",#w2)
   pause 500
loop
For a detailed explanation see my Code Snippet HERE.

Cheers, Alan.
 

hippy

Technical Support
Staff member
Depending on why you need two random variables, and what range of values each is, it may be better to have one variable kicked by RANDOM and just derive two random numbers by adjusting the maths which determines those. For example, two dice -
Code:
Random w0 : b2 = w0 / 19 // 6 + 1
Random w0 : b3 = w0 / 17 // 6 + 1
You might have to play with the expressions to get something which feels right.
 
Top