------art_15873_11735180.1181694401377
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 6/12/07, NAKAMURA, Hiroshi <nakahiro / sarion.co.jp> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all,
>
> # Especially to Technorama Ltd.
>
> We're discussing about introducing Random class for PRNG on ruby-dev ML.
>
>  * current rand and srand changes global state.  it should be the
>    source of a security problem sooner or later in this "framework" era.
>    (I claimed)
>  * Mats agreed to introduce a class for PRNG based on current Mersenne
>    Twister implementation.  class name is "Random".
>  * no plan to introduce another PRNG based on other PRNG algorithm.
>    MT is the only PRNG engine for "Random".
>  * we're now discussing what methods "Random" should have.
>
> Here's my proposal (no agreement for now);
>
> Random#integer(max)
> Ramdom#bytes(size)
> Random#float         # same as Random#rand(0).  not needed?
> Random#rand(max  )
> Random#srand(seed  il)
> Random#seedeed  il) # same as Random#srand(seed)
>
> Random.rand(max  ) # calls Random#rand(max) of the singleton Random
>                      # object which is initialized with the current
>                      # srand().
>
> rand(max  il)      # calls Random.rand(max)
> srand()              # srand() now takes no argument for 1.9.
>
> Comments needed.

Will it be core or standard? If we need to require 'random', then I
might suggest adding additional convenience methods. Attached is a
collection of such methods. Some can be especially useful, like
Array#shuffle.

T.

------art_15873_11735180.1181694401377
Content-Type: application/x-extension-rb; name=random.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_f2v2k8rw
Content-Disposition: attachment; filename="random.rb"

IyA9IEZJTEUKIyAgIHJhbmRvbS5yYgojCiMgPSBERVNDUklQVElPTgojICAgUmFuZG9taXphdGlv
biBtZXRob2RzLgojCiMgPSBDUkVESVRTCiMgICBDUkVESVQgSWxtYXJpIEhlaWtraW5lbiA8bWFp
bHRvOmtpZ0BtaXNmaXJpbmcubmV0PgojICAgQ1JFRElUIENocmlzdGlhbiBOZXVraXJjaGVuIDxt
YWlsdG86Y2huZXVraXJjaGVuQGdtYWlsLmNvbT4KCgpyZ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x1ZGU/KCAnYWJjJy5yYW5kX2luZGV4ICkgKSB9CiAgICBlbmQKCiAgICBkZWYgdGVzdF9y
YW5kX2J5dGUKICAgICAgcyA9ICdhYicKICAgICAgciA9IHMucmFuZF9ieXRlCiAgICAgIGFzc2Vy
dCggciA9PSA5NyB8fCByID09IDk4ICkKICAgIGVuZAoKICAgIGRlZiB0ZXN0X3JhbmRfYnl0ZQog
ICAgICBzID0gJ2FiJwogICAgICByID0gcy5yYW5kX2J5dGUKICAgICAgYXNzZXJ0KCByID09IDk3
IHx8IHIgPT0gOTggKQogICAgICBhc3NlcnQoIHMgPSAnYScgfHwgcyA9ICdiJyApCiAgICBlbmQK
CiAgICBkZWYgdGVzdF9zaHVmZmxlCiAgICAgIGFzc2VydF9ub3RoaW5nX3JhaXNlZCB7ICJhYmMg
MTIzIi5zaHVmZmxlIH0KICAgICAgI2Fzc2VydF9ub3RoaW5nX3JhaXNlZCB7ICJhYmMgMTIzIi5z
aHVmZmxlISB9CiAgICBlbmQKCiAgZW5kCgo9ZW5kCg------art_15873_11735180.1181694401377--