True Random Numbers?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nicholas Geraldi

    True Random Numbers?

    Im looking for a decent random number generator. Im looking to make a large
    number of random numbers (100 or so, if not more) in a short period of time
    (as fast as possible).

    the function i was using to get random numbers was

    Random rn = new Random(System.c urrentTimeMilli s());

    but it seems that the system doesn't update the milliseconds often enough to
    cause a true randomaziation (i ran just the System.currentT imeMillis() in a
    for loop 200 times and only got 3 unique results)

    any suggestions on how to get a quantity of real random numbers?

    Thanks
    Nick




    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • RGonzalez

    #2
    Re: True Random Numbers?

    I had a similar problem and added this in my loop:

    Thread.sleep(1, 2); //sleep fo 1 millis, 2 nanos to generate a more
    random seed

    It will slow the number generation but will guarantee uniquely random
    numbers.



    "Nicholas Geraldi" <nickgeraldi@ta conic.net> wrote in message
    news:3f89ecc2$1 [email protected] ups.com...[color=blue]
    > Im looking for a decent random number generator. Im looking to make a[/color]
    large[color=blue]
    > number of random numbers (100 or so, if not more) in a short period of[/color]
    time[color=blue]
    > (as fast as possible).
    >
    > the function i was using to get random numbers was
    >
    > Random rn = new Random(System.c urrentTimeMilli s());
    >
    > but it seems that the system doesn't update the milliseconds often enough[/color]
    to[color=blue]
    > cause a true randomaziation (i ran just the System.currentT imeMillis() in[/color]
    a[color=blue]
    > for loop 200 times and only got 3 unique results)
    >
    > any suggestions on how to get a quantity of real random numbers?
    >
    > Thanks
    > Nick
    >
    >
    >
    >
    > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
    >[/color]


    Comment

    • Christopher Browne

      #3
      Re: True Random Numbers?

      The world rejoiced as "Nicholas Geraldi" <nickgeraldi@ta conic.net> wrote:[color=blue]
      > any suggestions on how to get a quantity of real random numbers?[/color]

      Most operating systems these days have a device called "/dev/random",
      which collects values from hardware devices and combines it
      cryptographical ly to generate highly random values.

      Since that is a limited resource, there is often also a "/dev/urandom"
      device which uses crypto functions to generate very good pseudorandom
      data at faster rates...
      --
      If this was helpful, <http://svcs.affero.net/rm.php?r=cbbrow ne> rate me

      MICROS~1: Where do you want to go today? Linux: Been there, done
      that.

      Comment

      • Brian S O'Neill

        #4
        Re: True Random Numbers?

        You should take a look at the SecureRandom class that comes with Java.
        Of course, you don't want to re-seed or re-create it in the middle of
        the loop.

        Nicholas Geraldi wrote:[color=blue]
        > Im looking for a decent random number generator. Im looking to make a large
        > number of random numbers (100 or so, if not more) in a short period of time
        > (as fast as possible).
        >
        > the function i was using to get random numbers was
        >
        > Random rn = new Random(System.c urrentTimeMilli s());
        >
        > but it seems that the system doesn't update the milliseconds often enough to
        > cause a true randomaziation (i ran just the System.currentT imeMillis() in a
        > for loop 200 times and only got 3 unique results)
        >
        > any suggestions on how to get a quantity of real random numbers?
        >
        > Thanks
        > Nick
        >
        >
        >
        >
        > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
        > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
        > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----[/color]

        Comment

        • Nicholas Geraldi

          #5
          Re: True Random Numbers?

          could i get some documentation or an example of this?

          thanks,
          Nick




          -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
          http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
          -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

          Comment

          • Haakon Nilsen

            #6
            Re: True Random Numbers?

            Christopher Browne wrote:
            [color=blue]
            > The world rejoiced as "Nicholas Geraldi" <nickgeraldi@ta conic.net> wrote:[color=green]
            >> any suggestions on how to get a quantity of real random numbers?[/color]
            >
            > Most operating systems these days have a device called "/dev/random",[/color]

            Most *Unix*-like operating systems, that is. So, using /dev/random would
            not be platform independant, and probably not wanted anyway, since Nicholas
            seems to be a Windows user.

            That said, if you don't care about platform independance, /dev/(u)random is
            pretty nice.

            --
            Min virkelige mailadresse er rot13(unnxba@av yfra.pbz).

            Comment

            • Ty

              #7
              Re: True Random Numbers?

              Random Numbers
              int high=9;
              int low=4;
              range=high-low+1;

              int randomNumber = (int)Math.rando m(range+low);

              or for doubles

              double high=6.98;
              double low=5.43;
              double range=high-low;
              double randomNumber = Math.random(ran ge+low);

              Nicholas Geraldi <nickgeraldi@ta conic.net> wrote in message
              news:3f89ecc2$1 [email protected] ups.com...[color=blue]
              > Im looking for a decent random number generator. Im looking to make a[/color]
              large[color=blue]
              > number of random numbers (100 or so, if not more) in a short period of[/color]
              time[color=blue]
              > (as fast as possible).
              >
              > the function i was using to get random numbers was
              >
              > Random rn = new Random(System.c urrentTimeMilli s());
              >
              > but it seems that the system doesn't update the milliseconds often enough[/color]
              to[color=blue]
              > cause a true randomaziation (i ran just the System.currentT imeMillis() in[/color]
              a[color=blue]
              > for loop 200 times and only got 3 unique results)
              >
              > any suggestions on how to get a quantity of real random numbers?
              >
              > Thanks
              > Nick
              >
              >
              >
              >
              > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
              > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
              > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----[/color]


              Comment

              • Shyamal Prasad

                #8
                Re: True Random Numbers?

                "Nicholas" == Nicholas Geraldi <nickgeraldi@ta conic.net> writes:

                Nicholas> Im looking for a decent random number generator. Im
                Nicholas> looking to make a large number of random numbers (100 or
                Nicholas> so, if not more) in a short period of time (as fast as
                Nicholas> possible).

                What is wrong with just using a single java.util.Rando m object?

                Nicholas> the function i was using to get random numbers was

                Nicholas> Random rn = new Random(System.c urrentTimeMilli s());

                Nicholas> but it seems that the system doesn't update the
                Nicholas> milliseconds often enough to cause a true randomaziation
                Nicholas> (i ran just the System.currentT imeMillis() in a for loop
                Nicholas> 200 times and only got 3 unique results)

                What you are describing is probably not a random number
                generator. What you might want to do is generate a single Random
                instance at start up, seed it with the current time (which is not a
                good practice for cryptography type applications, but you did not tell
                us what you wanted to do with the numbers), and call nextInt() each
                time you want a new random number.

                Nicholas> any suggestions on how to get a quantity of real random
                Nicholas> numbers?

                Don't change your Random instance. Create one, seed it once, use it
                for as long as you can (see java.lang.math. Random() for example). Your
                problem is reduced to making sure you get a new seed each time your
                program runs. If you are not doing crypto stuff, use the current time.

                If the Random class is not good enough for you, I can't really
                help. Random number generation is hard! From what you described above
                I get the feeling you don't want random numbers, just "different"
                sequences.

                Cheers!
                Shyamal

                Comment

                • Nicholas Geraldi

                  #9
                  Re: True Random Numbers?

                  Yes you were right, i was recreating the random object each time. Silly
                  mistake =(

                  Seems to be working the way i want it too now, Thanks

                  Nick




                  -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                  http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                  -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                  Comment

                  • Glen Herrmannsfeldt

                    #10
                    Re: True Random Numbers?


                    "Nicholas Geraldi" <nickgeraldi@ta conic.net> wrote in message
                    news:3f89ecc2$1 [email protected] ups.com...[color=blue]
                    > Im looking for a decent random number generator. Im looking to make a[/color]
                    large[color=blue]
                    > number of random numbers (100 or so, if not more) in a short period of[/color]
                    time[color=blue]
                    > (as fast as possible).
                    >
                    > the function i was using to get random numbers was
                    >
                    > Random rn = new Random(System.c urrentTimeMilli s());
                    >
                    > but it seems that the system doesn't update the milliseconds often enough[/color]
                    to[color=blue]
                    > cause a true randomaziation (i ran just the System.currentT imeMillis() in[/color]
                    a[color=blue]
                    > for loop 200 times and only got 3 unique results)[/color]

                    What you describe is the creation of a Random number generator object.

                    Once you create a Random object, with appropriate seed, you use one of the
                    methods to get another random number.

                    Random rn = new Random(System.c urrentTimeMilli s());
                    for(i=0;i<10000 00;i++) println(rn.next Int(100));

                    Should print 1000000 random numbers between 0 and 99.

                    If you run it again, once the system clock has changed, it will print a
                    different set of 1000000 numbers.

                    You can use other methods in the Random class to get other types of results.

                    -- glen


                    Comment

                    • Oskar Sigvardsson

                      #11
                      Re: True Random Numbers?

                      If you want truly random numbers, you should use a website dedicated
                      to such things, like random.org. There you can request through HTTP a
                      set of random numbers (up to 10000 i belive). This is really only
                      necessary in cryptological purposes, for all other not-so-sensitive
                      stuff you could use java.lang.Rando m

                      Comment

                      Working...