Rand() not bieng very random

• 05-12-2007
Necrofear
Rand() not bieng very random
Sorry it's me again.

Anyway, the title pretty much explains it all. My program chooses five random numbers ranging from 1-5, (inclusive,) but it always chooses the same numbers in the same order. Is this normal? I ask simply because I wish to know the nature of rand(). I just can't see how any proccess a system performs can be random, as it has pre-set commands to determine these numbers. Can anyone explain the concept of random number generating? If you can please do as I am really lost.

Thanks for any replies.
Necrofear
• 05-12-2007
twomers
Have you seeded rand() Generate random numbers?
• 05-12-2007
Necrofear
No I hadn't. I wasn't sure how to generate a random seed, but I've just read the example you gave me, (Cheers for the link BTW,) and I'm going to try to use time as a seed like they did.

Necrofear

P.S. I like your avatar. House is an amazing show! Thanks again :D
• 05-12-2007
zacs7
[/offtopic]

Quote:

Originally Posted by twomers
Have you seeded rand() Generate random numbers?

Fran ? :P
• 05-12-2007
twomers
You talking about my sig, zacs7? I think it was Bernard, not Fran who said it.

• 05-12-2007
zacs7
Yeah I know :), just Fran was in there somewhere :), Ep with her shrinking walls methinks.
• 05-12-2007
Necrofear
Cheers for the rand() info.
I got the seed changing every execution now.

Thanks for the help!
Necrofear
• 05-12-2007
zacs7
Quote:

If you want to get different random numbers each time you run your program, you will also need to use the srand() function as well, as this will seed the generator. The srand() function is called only once during a programs execution.
....
• 05-12-2007
Necrofear
Quote:

Originally Posted by zacs7
....

???

If you mean what I think you mean by: ... , then I mean that every time the program is executed, it uses a different seed. Not that it changes seed halfway through. It use to always start at the same place.

If you don't mean what I think you mean however then I'm confused.
• 05-12-2007
zacs7
Bah, sorry I thought you ment every loop execution (iteration)
• 05-12-2007
learning
fyi they will only be pseudo random numbers not real randoms