Yet Another "Thickie" question / Random Range

I have to get my head around having “lots of memory” and not being limited
to 64k (readum… k) of data, like I used to be.

Anyone got a good algorythm laying around for the equivalent of random() in
python…

as in Random(x…y) to get a random number in the range x…y

Thanks,

Mark

[---------]
“I must hurry back to my comic book store, where I dispense the insults
rather than absorb them.”
[---------]

···

-----Original Message-----
From: Hal E. Fulton [mailto:hal9000@hypermetrics.com]
Sent: 23 September 2002 12:58
To: ruby-talk@ruby-lang.org
Subject: Re: Yet Another “Thickie” question from Mark

As for reading it “as needed”: That made
sense 20 years ago. But it’s only 107K.
That’s what, 1/5000th of your PC’s RAM?
I’d say: Put it in an array and forget it.

Hal

NOTICE: This e-mail and any attachment(s) may contain confidential and
proprietary information of Goss International Corporation and/or its
subsidiaries and may be legally privileged. This e-mail is intended solely
for the addressee. If you are not the addressee, dissemination, copying or
other use of this e-mail or any of its content is strictly prohibited and
may be unlawful. If you are not the intended recipient please inform the
sender immediately and destroy the e-mail and any copies. All liability for
viruses is excluded to the fullest extent permitted by law. Any views
expressed in this message are those of the individual sender. No contract
may be construed by this e-mail.

In article 46487A0D3619D511BF860000F6B99827D2C5DE@PRESGGS17, Firestone,
Mark - Technical Support wrote:

Anyone got a good algorythm laying around for the equivalent of random() in
python…

as in Random(x…y) to get a random number in the range x…y

If you’re talking integers then this could be the basis for something:

def random(r)
# assume r is a range of integers first < last
r.first + rand(r.last - r.first + (r.exclude_end? ? 0 : 1))
end

(no error checking, but

random(6 … 10) # => an integer from 6, 7, 8, 9, 10
random(6 … 10) # => an integer from 6, 7, 8, 9

seems reasonable to me. I don’t know what python does…)

Hope this helps,

Mike

···


mike@stok.co.uk | The “`Stok’ disclaimers” apply.
http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA
mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60
http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA