Hello all,
I have a question about RND, although it does not cause any problem to what i am making (difference is very small)
I need amstrad to choose randomly between 3 options. So what i did is define a variable through RND (x=RND) and then examine if x<0.3333333 (option A), if x>0.66666666 (option B) and if x>0.33333333 and x<0.66666666 (option C). I am using also RANDOMIZE TIME to avoid having the same sequence every time amstrad is turning on.
It is working fine. What i noticed is that rarely (at about 1/20 times), RND is not between 0 and 1, but more (as you see on screenshot 7,18). This doesn't cause problem to me, as it is rare, but i wonder why this is happening. Does anyone has an idea?
Many thx!
It's not "7.18". BASIC displays numbers smaller than 0.1 in scientific notation, hence the "E-02" at the end, which is shorthand for "x 10-2".
7.18285E-02 is 0.0718285!
Quote from: pelrun on 12:28, 03 March 18
It's not "7.18". BASIC displays numbers smaller than 0.1 in scientific notation, hence the "E-02" at the end, which is shorthand for "x 10-2".
7.18285E-02 is 0.0718285!
Many thx Pelrun! So, hopefully, i don't have to change anything!! It makes sense now!
In my opinion, it will be better to avoid the use of several conditionals (slow sentences). For example:
10 RANDOMIZE TIME
20 A%=FIX(RND*3)+1:PRINT A%:GOTO 20
to be able to use the sentence ON..GOTO or ON..GOSUB:
10 DEFINT A-Z:RANDOMIZE TIME
20 ON FIX(RND*3)+1 GOTO 30,40,50
30 A=A+1:GOTO 20
40 B=B+1:GOTO 20
50 C=C+1:GOTO 20
option = int(RND*3)
Many thx to all for your answers!!!
Quote from: GUNHED on 13:03, 04 March 18
option = int(RND*3)
You're right, in this case both can be used, but FIX is slightly faster than INT ;)
A small improvement from my previous:
10 DEFINT A-Z:RANDOMIZE TIME
20 ON 0.5+RND*3 GOTO 30,40,50
30 A=A+1:GOTO 20
40 B=B+1:GOTO 20
50 C=C+1:GOTO 20