This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

srand() / rand()

Hello,

Is there a way to have real different random numbers?
For the moment, I'm using the rand() function, but this one is generating the same sequence over and over again. I have to unpower my application to have a new series of random numbers.
I'm now 'experimenting' (what's in a word...) with the following construction:

.
.
.
srand( rand() );
.
.
.
RandomNumber = ( rand() / 256 );
.
.
.

Is there a better way to do this?

Rgds,

--Geert

Parents
  • The whole subject of random numbers is vast. Any random number sequence produced by a deterministic process must pseudo-random. If you are looking for pseudo-random number generators that are good (in the statistical sense try this web-site:

    http://mandala.co.uk/links/random/

    No matter how good the generator may be, it is still deterministic.

    For really random numbers, you will have to find a source of randomness that the micro can access and either use this for all your random numbers or to seed a good generator. Typical sources include timing mechanical and user input events.

Reply
  • The whole subject of random numbers is vast. Any random number sequence produced by a deterministic process must pseudo-random. If you are looking for pseudo-random number generators that are good (in the statistical sense try this web-site:

    http://mandala.co.uk/links/random/

    No matter how good the generator may be, it is still deterministic.

    For really random numbers, you will have to find a source of randomness that the micro can access and either use this for all your random numbers or to seed a good generator. Typical sources include timing mechanical and user input events.

Children