[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random Statement
- Subject: Re: Random Statement
- From: rubywand@aol.com
- Date: 1996/12/01
- Newsgroups: comp.sys.apple2
- Organization: America Online, Inc. (1-800-827-6364) (1.13)
- References: <01bbde4f$4210cac0$LocalHost@Administrator>
In article <01bbde4f$4210cac0$LocalHost@Administrator>, "Diego P. Vasquez
B." <dvasquez@datasrv.com> writes:
>
>Please clarify... I think that maybe I could help, but I did'n quite
>understand your message. Maybe the full code to be tried will do.
>C'YA!
>
>tbird@skyenet.net wrote in article <57lu0m$3po@news.skyenet.net>...
>> I use this, why won't it work...???
>>
>> 10 let a = Rnd(1)*170
>> 20 if a <20 then goto (somewhere)
>> 30 if a >150 then goto (somewhere else)
>>
>> howcome sometimes in the middle of the program the number from the
random
>
>> statement is under 20 and over 150. A rnd(20)*150 isn't correct...
I'm
>> stuck,please help...?
>>
>
>
The confusing thing about this question is the code in Lines 20 and
30. If you want A to be in the range 20-150, why would Lines 20 and 30
send you anywhere but Line 10 (i.e. to try for another number that fits)?
This thread got deleted after Nathan's response; so, this may be a
repeat:
10 A= 20 + INT( RND(1) * 131)
will give nice clean integers, like 33, 87, 121, ..., with a minimum
possible value of 20 and a maximum possible value of 150.
If you want the random numbers between 20 and 150 to, possibly, have
fractional parts, then
10 A= 20 + RND(1) * 130.1: IF A>150 then A= 150
will give the numbers, like 33, 87.557, 121.2, ..., with a minimum
possible value of 20 and a maximum possible value of 150.
Lines 20 and 30 can be deleted since A will never be less than 20 or
greater than 150. (By the way, it is best to stick with the Applesoft
BASIC convention of using upper-case everywhere except in text you want to
display in lower-case.)
Rubywand