Math.random()

Discussion in 'Java' started by Aaron Fude, May 28, 2004.

  1. Aaron Fude

    Aaron Fude Guest

    Hi,

    Is there a way to reset the seed globally so that Math.random() starts
    returning the same numbers every time the program is executed or is using
    java.util.Random the only way to it?

    Thanks,

    Aaron Fude
     
    Aaron Fude, May 28, 2004
    #1
    1. Advertising

  2. Aaron Fude

    Roedy Green Guest

    On Fri, 28 May 2004 06:52:06 GMT, "Aaron Fude" <>
    wrote or quoted :

    >Is there a way to reset the seed globally so that Math.random() starts
    >returning the same numbers every time the program is executed or is using
    >java.util.Random the only way to it?


    you need java.util.Random. Math.random is just a shortcut.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 28, 2004
    #2
    1. Advertising

  3. Aaron Fude

    Aaron Fude Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Fri, 28 May 2004 06:52:06 GMT, "Aaron Fude" <>
    > wrote or quoted :
    >
    > >Is there a way to reset the seed globally so that Math.random() starts
    > >returning the same numbers every time the program is executed or is using
    > >java.util.Random the only way to it?

    >
    > you need java.util.Random. Math.random is just a shortcut.
    >


    Which means that I need a class with contains a static instance of
    java.util.Random (if I want the setting to be program-wide)? Wondering why
    java does not provide such a class.
    > --
    > Canadian Mind Products, Roedy Green.
    > Coaching, problem solving, economical contract programming.
    > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Aaron Fude, May 28, 2004
    #3
  4. Aaron Fude wrote:
    > Which means that I need a class with contains a static instance of
    > java.util.Random (if I want the setting to be program-wide)?


    Not necessarily. What you most need is to initialize your Random objects
    with a fixed seed.

    > Wondering why
    > java does not provide such a class.


    Because it's trivial to do and not needed all that often?
     
    Michael Borgwardt, May 28, 2004
    #4
  5. Aaron Fude

    Oscar kind Guest

    Aaron Fude <> wrote:
    >
    > "Roedy Green" <> wrote in message
    > news:...
    >>
    >> you need java.util.Random. Math.random is just a shortcut.

    >
    > Which means that I need a class with contains a static instance of
    > java.util.Random (if I want the setting to be program-wide)? Wondering why
    > java does not provide such a class.


    Java does; by way of Math.random(). It's just that if you need a seeded
    random generator, there are so many possibilities that it's better to
    create a singleton in your program (at least IMHO).


    Oscar

    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, May 28, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chirs
    Replies:
    18
    Views:
    794
    Chris Uppal
    Mar 2, 2004
  2. AciD_X
    Replies:
    4
    Views:
    8,153
    Jonathan Turkanis
    Apr 1, 2004
  3. Mark Healey
    Replies:
    7
    Views:
    1,543
    Tim Prince
    May 22, 2006
  4. globalrev
    Replies:
    4
    Views:
    797
    Gabriel Genellina
    Apr 20, 2008
  5. VK
    Replies:
    15
    Views:
    1,283
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page