Welcome Guest
Log In | Register )
You last visited December 2, 2016, 2:44 pm
All times shown are
Eastern Time (GMT-5:00)

Random Number Generators... ?

Topic closed. 10 replies. Last post 13 years ago by hypersoniq.

Page 1 of 1
PrintE-mailLink
hypersoniq's avatar - 8ball
Pennsylvania
United States
Member #1340
April 6, 2003
2450 Posts
Offline
Posted: June 21, 2003, 6:43 pm - IP Logged

Anyone know what's under the hood of most RNG functions?

Any way to reverse-solve a number to find it's seed? Anyone know the code for how excel's RAND() function works?

 

    RJOh's avatar - chipmunk
    mid-Ohio
    United States
    Member #9
    March 24, 2001
    19814 Posts
    Online
    Posted: June 21, 2003, 10:11 pm - IP Logged

    When a program is written, any seed number can be entered by the programmer for testing, however after program is completed,  a routine may be included to get a random seed from the computer clock.  If Excel doesn't give you the option of entering your own seed then it probably use the computer clock.  Check your manual, it may have a way for you to formulate your own seed for testing.

    RJOh

      hypersoniq's avatar - 8ball
      Pennsylvania
      United States
      Member #1340
      April 6, 2003
      2450 Posts
      Offline
      Posted: June 22, 2003, 6:14 am - IP Logged

      For excel, I enter the following (for example) to generate a red ball pick...

      RAND()*(42-1)+1

      I'm just interested to see the code behind the RAND() function

       

        Avatar

        United States
        Member #403
        June 15, 2002
        166 Posts
        Offline
        Posted: June 22, 2003, 6:47 am - IP Logged

        I use this formula for Pick3:



        =MOD((INT(RAND()*10)+1),10)



        The "clock" thing sounds logical to me.



        Although, you've got me thinking about it. I believe I'll do some checking and see what I can find out.



        Thanks

          Avatar

          United States
          Member #403
          June 15, 2002
          166 Posts
          Offline
          Posted: June 22, 2003, 6:51 am - IP Logged

          Check out this site:



          http://www-user.tu-chemnitz.de/~anhe/DOCU/C/C/FUNCTIONS/rand.html



          It has some stuff on it about the seed.



          Or, you can do a search in Google "rand function"



          Good luck and please post if you find your answer.



          Thanks

            hypersoniq's avatar - 8ball
            Pennsylvania
            United States
            Member #1340
            April 6, 2003
            2450 Posts
            Offline
            Posted: June 22, 2003, 8:15 am - IP Logged

            http://dada.perl.it/shootout/random_allsrc.html

             

            seems to cover all the bases... Now if it only had a "for dummies" guide...

              Avatar

              United States
              Member #403
              June 15, 2002
              166 Posts
              Offline
              Posted: June 22, 2003, 8:35 am - IP Logged

              Boy! That looks r-e-a-l interesting.



              I would definately be the "dummy" on that one. It's a little over my head.

              Maybe RJOH can help.



              Good luck.

                RJOh's avatar - chipmunk
                mid-Ohio
                United States
                Member #9
                March 24, 2001
                19814 Posts
                Online
                Posted: June 23, 2003, 10:47 am - IP Logged

                That site shows that there are lots of ideas to formulate a RND fuction.  If you want to test your RND fuction just write a loop of maybe 1000 cycles  to generate numbers 1-10 and count them.  The count for each number should be pretty close, if not then your random picks are bias.

                RJOh

                  Pacific Northwest
                  United States
                  Member #1229
                  March 6, 2003
                  707 Posts
                  Offline
                  Posted: July 3, 2003, 12:25 pm - IP Logged

                  Hank,

                  Curious: What is the signifcance of

                  =MOD((INT(RAND()*10)+1),10)

                  Seems too big of a formula to create numbers between 0 and 9.

                  What you are doing is, with the +1 is creating numbers between 1 and 10. Once you hit a 10 the Modulo 10 makes it a 0 again.

                  The simpler version =INT(RAND()*10) would do the same thing.

                  Or do I miss something?

                  Good Luck

                  ME

                   

                    Pacific Northwest
                    United States
                    Member #1229
                    March 6, 2003
                    707 Posts
                    Offline
                    Posted: July 3, 2003, 12:43 pm - IP Logged

                    Interesting topic...

                    The page color=#0000cchttp://dada.perl.it/shootout/random_allsrc.html shows actually a basic Pseudorandom Number Generator in many different scripting languages. According to the "shootout" they all come up with exaclty the same number results.

                    For the "standard" user the random numbers implemented in javascript, VB, Excel etc. should usually not require to program your own Random Generating Routine. If the programming language that you are using does not have a random function (other than ancient COBOL I would not know any) you might need it but hmmm....

                    To answer the original question....

                    In Microsoft Excel, the RAND function uses the following iterative method to calculate pseudo-random numbers:

                    The first random number:

                      random_number=fractional part of (9821 * r + 0.211327),
                      where r = .5
                    Successive random numbers:

                      random_number=fractional part of (9821 * r + 0.211327),
                      where r = the previous random number

                    According to Microsoft this formula will provide up to 1 million different numbers.

                    Good Luck,

                    ME

                      hypersoniq's avatar - 8ball
                      Pennsylvania
                      United States
                      Member #1340
                      April 6, 2003
                      2450 Posts
                      Offline
                      Posted: July 3, 2003, 1:19 pm - IP Logged

                      thanks Everett!