Thread: Rand() not bieng very random

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    183

    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

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Have you seeded rand() Generate random numbers?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    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.

    Thanks for the reply.
    Necrofear

    P.S. I like your avatar. House is an amazing show! Thanks again

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    [/offtopic]

    Quote Originally Posted by twomers View Post
    Have you seeded rand() Generate random numbers?
    Fran ? :P

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You talking about my sig, zacs7? I think it was Bernard, not Fran who said it.

    Here's more reading about rand().

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Yeah I know , just Fran was in there somewhere , Ep with her shrinking walls methinks.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Cheers for the rand() info.
    I got the seed changing every execution now.

    Thanks for the help!
    Necrofear
    Last edited by Necrofear; 05-12-2007 at 08:26 AM.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    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.
    ....

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    Quote Originally Posted by zacs7 View Post
    ....
    ???

    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.

  10. #10
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Bah, sorry I thought you ment every loop execution (iteration)

  11. #11
    Registered User learning's Avatar
    Join Date
    May 2007
    Location
    australia
    Posts
    36
    fyi they will only be pseudo random numbers not real randoms
    at night uv comes alive

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random to int?
    By psyadam in forum C# Programming
    Replies: 7
    Last Post: 07-22-2008, 08:09 PM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM