1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How reliable are random number generators?

Discussion in 'Programming' started by vtgorilla, Mar 19, 2007.

  1. #1
    I have thought of a new concept that I may launch soon. However, it will rely on a random number generator (or something similar) to function properly. Does anyone know of a reliable one to download or use?

    How reliable are they? truly random?

    Thanks
     
    vtgorilla, Mar 19, 2007 IP
  2. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can never have truly random numbers on a computer. They are pretty damn random to the casual viewer, but mathematically they are not. Not sure if that means anything to you or not.

    If you have *nix hosting you can use the command line command "random", or just use PHP's random function or something.

    Really depends on what you need it for and what you expect as far as "reliability" goes?
     
    MattD, Mar 19, 2007 IP
    Artisan likes this.
  3. vtgorilla

    vtgorilla Peon

    Messages:
    137
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I guess as long as it gives the appearance of random to the user it would suit my needs...but I'd rather not get sued ;)

    As long as no one knows that its not 'truly' random then it wouldn't matter...

    Thanks for the help!
     
    vtgorilla, Mar 19, 2007 IP
  4. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #4
    An important part of generating a random number is the seed value. Some libraries now try to start the generator with something other than just time to get a more random result. If you use time and the generator is called at the same instant, the same number could be generated for each individual and the same second number and so forth. Some people have tried to get around this by looking for other data to help generator a more random seed, combining time with process ID numbers and/or free memory and/or some other data bits readily available from the host computer. Internet applications could use time plus IP addresses as a seed value -- though this breaks down if two people from same IP access the application at the same moment. It is an interesting topic and many people have worked on the science of generating better random numbers. A search will yield innumerable articles on the topic and ideas for ensuring a more unpredictable random number is generated . . . especially if you are worried about legal liability.
     
    clancey, Mar 19, 2007 IP
    Artisan likes this.
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Barti1987, Mar 19, 2007 IP
    Artisan likes this.
  6. SeLfkiLL

    SeLfkiLL Active Member

    Messages:
    85
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    50
    #6
    If you really want random numbers, you can make something that connects to http://www.random.org/nform.html to get a list of random numbers.
     
    SeLfkiLL, Mar 19, 2007 IP
    Artisan likes this.
  7. Artisan

    Artisan Well-Known Member

    Messages:
    616
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    128
    #7
    Most Unix like operating systems have special device name for the stream of high quality random numbers, but this stream is rather slow sometimes, thus for the most purposes it would be best to use its output as a seed for the pseudo random numbers generator.

    /dev/random
     
    Artisan, Mar 31, 2007 IP
  8. Artisan

    Artisan Well-Known Member

    Messages:
    616
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    128
    #8
    And the best generator of the pseudo random numbers which I know of is the Mersenne Twister, a very fast pseudo random number generator of period (2^19937)-1.

    http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
     
    Artisan, Mar 31, 2007 IP
  9. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #9
    As Artisan said, most random number generators are actually pseudo random number generators.

    It's been a while since I've had my head buried in the guts of random generators (did lots of work with this stuff years ago at a very low level), but IIRC...

    Most common/popular random number generators are of the "linear congruential generator" (or LCG for short) variety, and these do have a certain periodicity, meaning that in time the pseudo-random sequence will roll over and start to repeat itself.

    The peridocity and other factors of an LCG are known up front, based on the LCG algorithm itself and the initial input parameters.

    You can determine the quality of a random number generator by seeing how well it truly does generate random number by using various statistical "goodnes of fit" tests. Two common tests for random number generators (assuming you know the distributions) are the chi-squared test and the kolmogorov-smirnov test (no relation to the vodka dude).

    Simulation Modelling and Analysis by Law & Kelton has excellent coverage of random generators and goodnes-of-fit tests.

    If you don't want to go the dead tree route, Google the terms "LCG generator" "chi squared test" and "kolmogorov smirnov" (not all at once). Those should get you going.
     
    sea otter, Mar 31, 2007 IP
    Artisan likes this.