Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Multiple random number generators

Reply
Thread Tools

Multiple random number generators

 
 
Frantisek Fuka
Guest
Posts: n/a
 
      04-29-2006
It seems to me that rand and srand can only use the single "global"
psudorandom generator. Is there a possibility to have several random
sequences based on different seeds, all available at the same time?

I could probably write this myself but I don't want to reinvent the
wheel.

I don't need the generator to be "cryptographically secure" or have
extremely long periods (I'll rarely use random sequences longer than
100 numbers from any single generator) but I need to have several
generators available at the same time and possibility to "reset" their
sequences individually.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-30-2006
Frantisek Fuka wrote:
> It seems to me that rand and srand can only use the single "global"
> psudorandom generator. Is there a possibility to have several random
> sequences based on different seeds, all available at the same time?
>
> I could probably write this myself but I don't want to reinvent the
> wheel.
>
> I don't need the generator to be "cryptographically secure" or have
> extremely long periods (I'll rarely use random sequences longer than
> 100 numbers from any single generator) but I need to have several
> generators available at the same time and possibility to "reset" their
> sequences individually.
>

You'll find quite a lot of stuff on RAA

http://raa.ruby-lang.org/search.rhtml?search=random
http://raa.ruby-lang.org/cat.rhtml?c...ory_minor=Math

Kind regards

robert
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      04-30-2006
Robert Klemme <(E-Mail Removed)> wrote:
> Frantisek Fuka wrote:
>> It seems to me that rand and srand can only use the single "global"
>> psudorandom generator. Is there a possibility to have several random
>> sequences based on different seeds, all available at the same time?
>>
>> I could probably write this myself but I don't want to reinvent the
>> wheel.
>>
>> I don't need the generator to be "cryptographically secure" or have
>> extremely long periods (I'll rarely use random sequences longer than
>> 100 numbers from any single generator) but I need to have several
>> generators available at the same time and possibility to "reset"
>> their sequences individually.
>>

> You'll find quite a lot of stuff on RAA
>
> http://raa.ruby-lang.org/search.rhtml?search=random
> http://raa.ruby-lang.org/cat.rhtml?c...ory_minor=Math
>
> Kind regards
>
> robert


PS: if it's for testing purposes only and you have small sequences you could
pre generate them (or store the sequence while you generate it) and this
allow for easy reset.

class MyRandom
def initialize(size = 0)
@rands = []
@index = 0
size.times { rand }
reset
end

def rand(limit = 0)
x = get_next
limit == 0 ? x : (limit * x).to_i
end

def reset() @index = 0 end

def clear()
@rands = []
reset
end

private

def get_next
res = @rands[@index] ||= Kernel.rand
@index += 1
res
end
end


Kind regards

robert

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ideal interface for Random Number Generators? orz C++ 39 06-23-2010 09:20 AM
Separate random number generators? Bart Braem Ruby 18 01-27-2009 10:36 AM
[ANN] Uncommons Maths 1.0.2 (Random number generators and other utilities) Daniel Dyer Java 15 11-26-2007 03:22 PM
Random Number Generators.... RadiationX C Programming 40 03-03-2006 01:56 AM
random number generators cesco C++ 4 02-03-2006 09:47 PM



Advertisments