TIB: Re: RE: Re: randInt on the 89


[Prev][Next][Index][Thread]

TIB: Re: RE: Re: randInt on the 89



Hmmm...what exactly does putting a number inside the rand() function's parentheses do? I never did figure that out...
        --Chris
----- Original Message -----
From: Ethereal Knight (aka Idiot)
To: ti-basic@lists.ticalc.org
Sent: Saturday, November 11, 2000 11:40 PM
Subject: TIB: RE: Re: randInt on the 89

or

Define randint(low,high)=low+rand(high-low+1)-1

 

-----Original Message-----
From: owner-ti-basic@lists.ticalc.org [mailto:owner-ti-basic@lists.ticalc.org]On Behalf Of Daniel Bishop
Sent: Saturday, November 11, 2000 10:10 PM
To: ti-basic@lists.ticalc.org
Subject: TIB: Re: randInt on the 89

 

Define randint(low,high)=low+floor(rand()*(high-low+1))

 

----- Original Message -----

From: Slim W. Skawalker

To: TI-BASIC Group

Sent: Saturday, November 11, 2000 19:04

Subject: TIB: randInt on the 89

 

Hello everybody...here's a routine I came up with for the 89 for generating a random integer between a low and a high integer -- same as the randInt function on the 86. I hope you find this useful. There is only one problem -- because I wrote it to work with negative numbers, too (like if you wanted a number between -5 and 5) it won't work if you use too wide a range of numbers because the list, l, gets too big. If anybody out there can fix this, I would greatly appreciate it if you would reply with your solution. Thanks!

 

randint(low,high)

Func

Local l,z

seq(x,x,low,high)->l

Lbl getz

iPart(round(10^(dim(string(dim(l)))-1)*rand(),dim(string(dim(l)))-1))->z

If z>dim(l) or z=0:Goto getz

Return l[z]

EndFunc

 

     --Chris


References: