Random Numbers help

Hey guys, I thought I would drop by here for help.

I am writing a program where I need to generate a random set of lest say 50 numbers from 8 to 11, and have a new set of 50 if I restart the program, or some condition is not met.

Here is part of my code that generates a random set of 50.
while(i<=49){
ledB*=random(8,12);*

  • i++;*
    }
    The problem is that when I restart the program, I get an identical set of 50 AGAIN. But what I need is a new set of 50.
    If the function random(min,max) is not random what is it used for?
    Thank you

You need to 'seed' the random number generator in the setup portion of your sketch using the randomSeed(seed) function:

http://arduino.cc/en/Reference/RandomSeed

That reference shows using a analogRead on an unconnected analog pin to get a different seed number for each startup of the program. There is a active posting around here on trying to find a better source for a seed number that is truly random, check it out.

Lefty

Thanks retrolefty,

Want to make something sure.

The way random number generator, gets the numbers is by taking a number say 9999 and applying a formula to it.

When you do randomSeed, it randomizes the number that it applies the formula to.

Am I right? If that is the case what is the purpose of not randomseeding?

randomSeed just specifies the initial number. I don't know the default, maybe zero.

Why not do it? Well you may be testing some code and want the same test data every time through.

The active link to automatically reseed the RNG at startup - http://arduino.cc/forum/index.php/topic,66206.msg537783.html#msg537783 -