Generating random numbers?

Discussion in 'Ruby' started by Harry Ohlsen, Jul 28, 2003.

  1. Harry Ohlsen

    Harry Ohlsen Guest

    Can someone remind me of the name for the class/method for generating random
    numbers? I did a quick grep through the library and a google, but all I
    found was a project that plans to improve the random number generator(s).

    Thanks in advance,

    Harry O.
     
    Harry Ohlsen, Jul 28, 2003
    #1
    1. Advertising

  2. Harry Ohlsen

    Cedric Foll Guest

    Harry Ohlsen wrote:

    > Can someone remind me of the name for the class/method for generating random
    > numbers? I did a quick grep through the library and a google, but all I
    > found was a project that plans to improve the random number generator(s).
    >
    > Thanks in advance,
    >
    > Harry O.
    >
    >

    oban:~# irb
    irb(main):001:0> rand(10)
    => 8

    You have the rand method.
    rand(n) return a number in [1..n-1].
     
    Cedric Foll, Jul 28, 2003
    #2
    1. Advertising

  3. Harry Ohlsen

    Ben Giddings Guest

    On Mon July 28 2003 5:19 pm, Harry Ohlsen wrote:
    > Can someone remind me of the name for the class/method for generating random
    > numbers? I did a quick grep through the library and a google, but all I
    > found was a project that plans to improve the random number generator(s).


    Kernel::rand

    irb(main):012:0> rand
    => 0.1986612797
    irb(main):013:0> rand(5)
    => 4

    Use the first for a floating point random between 0 and 1, the second for an
    integer rand between 0 and the number.

    http://www.rubycentral.com/book/ref_m_kernel.html#Kernel.rand

    Ben
     
    Ben Giddings, Jul 28, 2003
    #3
  4. On Tue, Jul 29, 2003 at 06:19:58AM +0900, Harry Ohlsen wrote:
    > Can someone remind me of the name for the class/method for generating random
    > numbers? I did a quick grep through the library and a google, but all I
    > found was a project that plans to improve the random number generator(s).


    Kernel::rand

    Seed it via:

    Kernel::srand

    HTH,

    Brandon D. Valentine
    --
    http://www.geekpunk.net
    Pseudo-Random Googlism: texas is the reason do you know who you are?
     
    Brandon D. Valentine, Jul 28, 2003
    #4
  5. Saluton!

    * Harry Ohlsen; 2003-07-28, 21:35 UTC:
    > Can someone remind me of the name for the class/method for
    > generating random numbers?


    Nobody did ask this so far: What kind of random numbers do you need
    and for what purpose.

    Ruby's RNG may be nice for Monte Carlo simulations (because it has a
    very large period) but it is NOT SECURE for CRYPTOGRAPHY as it is.
    You may wish to visit

    http://www.math.keio.ac.jp/matumoto/emt.html

    Gis,

    Josef 'Jupp' Schugt
    --
    N'attribuez jamais à la malice ce que l'incompétence explique !
    -- Napoléon
     
    Josef 'Jupp' Schugt, Jul 30, 2003
    #5
  6. >>>>> "JS" == Josef Schugt <Josef> writes:

    JS> Saluton! * Harry Ohlsen; 2003-07-28, 21:35 UTC:
    >> Can someone remind me of the name for the class/method for
    >> generating random numbers?


    JS> Nobody did ask this so far: What kind of random numbers do you
    JS> need and for what purpose.

    JS> Ruby's RNG may be nice for Monte Carlo simulations (because it
    JS> has a very large period) but it is NOT SECURE for CRYPTOGRAPHY
    JS> as it is. You may wish to visit

    JS> http://www.math.keio.ac.jp/matumoto/emt.html

    JS> Gis,

    JS> Josef 'Jupp' Schugt -- N'attribuez jamais à la malice ce que
    JS> l'incompétence explique ! -- Napoléon

    Actually, Ruby's RNG isn't so great for Monte Carlo or discrete event
    simulations. I'd only use it for games. The problem isn't the
    quality of the generator (I think Matz is using the Mersenne twister
    algorithm). It's that "randomness" is obtained by a method rather
    than a Random class which can instantiate Random objects. If there
    were separate random objects, each of which maintained its own seed
    state, it would be much easier to create designed experiments with
    common or antithetic random variates which you could exploit for
    variance reduction. Having a method restricts you to a single stream
    of randomness unless you're willing to go through contortions.

    --paul
     
    Paul J. Sanchez, Jul 31, 2003
    #6
    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. Wally
    Replies:
    1
    Views:
    2,836
    pvdg42
    Mar 20, 2006
  2. Replies:
    3
    Views:
    12,761
    Boris Stumm
    Feb 9, 2006
  3. lallous
    Replies:
    5
    Views:
    615
    lallous
    Oct 20, 2003
  4. sugaray

    problem with generating random numbers !

    sugaray, Sep 13, 2003, in forum: C Programming
    Replies:
    2
    Views:
    401
    Tom Zych
    Sep 14, 2003
  5. Intaek LIM
    Replies:
    1
    Views:
    440
    Andreas Kahari
    Oct 31, 2003
Loading...

Share This Page