random number in C

Sharky Forums


Results 1 to 4 of 4

Thread: random number in C

  1. #1
    Reef Shark Squirlenutz's Avatar
    Join Date
    Mar 2003
    Posts
    492

    random number in C

    I wrote a little program for a friend of mine that will randomly display a new guitar chord in intervals of the user's choosing. The only issue with it is that the random function produces the same exact "random" results every time the program is run. Right now I'm doing
    rand()%20
    . Any other way of doing this that will produce truly random numbers?
    System:
    Core 2 Duo e8400
    ASUS P5Q Pro
    4 gigs DDR2 PC2 8500 Mushkin Ram
    EVGA GTX 260
    WD 74 gig Raptor
    Maxtor 300 gig Diamond Max
    Maxtor 1 tb
    Antec NeoPower 550w

  2. #2
    Hammerhead Shark
    Join Date
    Feb 2001
    Posts
    1,612
    you need to seed the rng first. Customary is to do something like srand(time()) or however you get the time... basically just call srand with a number that changes each run.

  3. #3
    Ultra Great White Shark!! richardginn's Avatar
    Join Date
    Feb 2001
    Posts
    16,118
    www.myeducational plan.com-come see my plan to fix the USA educational system. I hope this is sig legal. Major Site Design Update on July 18, 2006. On June 18, 2009 passed the 10,000 post mark. December 24, 2009: Major Theme change and more....

  4. #4
    Reef Shark Squirlenutz's Avatar
    Join Date
    Mar 2003
    Posts
    492
    awesome, thank you very much
    System:
    Core 2 Duo e8400
    ASUS P5Q Pro
    4 gigs DDR2 PC2 8500 Mushkin Ram
    EVGA GTX 260
    WD 74 gig Raptor
    Maxtor 300 gig Diamond Max
    Maxtor 1 tb
    Antec NeoPower 550w

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •