random()

Discussion in 'Mac Programming' started by MDMstudios, Apr 9, 2008.

  1. macrumors member

    Joined:
    Mar 18, 2008
    #1
    I'm making a program that needs to produce a different random number each time the program is used, the problem is when I use the random() function, it produces the same random number each time I use it.
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    use randomize() to use a clock-based seed.

    -Lee
     
  3. macrumors member

    cruzrojas

    Joined:
    Mar 26, 2007
    Location:
    USA
    #3
    You need to seed your program with srandom(unsigned long seed), if you use the same seed in 2 different runs you will get the same result every time, which is useful for debugging. Once you want to deploy your application you can use the computer time as the seed and this will produce different seed every time.
     

Share This Page