Dear fellow Flowcode users
My wish is to create a small program which can generate a random variable and then make a random led turn on.
So far I have two LEDarrays with 3 leds in each and I want one LED to be turned on in each LEDarray, the LED should be selected by the random variable. As I do not want the same LED in each LEDarray to turn on, I have made two different random variables. BUT the two random variables generate the same random value each time.
My quenstion is: How can I make different variables generate different values in the same program?
I really hope anybody is able to help. If there is any quenstions please ask me.
Best regards
Aleksander Rosenkilde Kristiansen
P.S. I have attached my program.
Random LED's
Moderator: Benj
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Random LED's
Hello Aleksander.
Flowcode has a random number function, random(), built in. This should return a different value each time you call it.
If this is not what you are after or are using (sorry - I have Linux at home so can not see your program) Here is some pseudo-code for a simple random 16-bit number. Note the 'randval' global variable is not initialised at the start. This helps with a different random number each time.
You can call this constantly in a timer interrupt if you want, or each time you need it. Then, if you want a value between 0 and N do:
It may also help to look at Martins lottery generator, here:
http://www.matrixmultimedia.com/mmforum ... 885#p22091
Good luck,
Jonny
Flowcode has a random number function, random(), built in. This should return a different value each time you call it.
If this is not what you are after or are using (sorry - I have Linux at home so can not see your program) Here is some pseudo-code for a simple random 16-bit number. Note the 'randval' global variable is not initialised at the start. This helps with a different random number each time.
Code: Select all
randval = randval + 0xCA56
randval = (randval >> 3) + (randval << 13)
.Return = randval
Code: Select all
value = GetRandom()
value = value MOD N
http://www.matrixmultimedia.com/mmforum ... 885#p22091
Good luck,
Jonny