News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Question for RND

Started by skylas, 12:13, 03 March 18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

skylas

 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!
Web: https://amstradsakis.blogspot.com
Twitter: https://twitter.com/AmstradSakis
My programs (only BASIC):
RETRO-LOADSHEET!, PENALTY KICKS!, CAPITAL QUIZ!, CAPITAL QUIZ 2! (Reverse edition), HEADS OR TAILS (ΚΟΡΩΝΑ/ΓΡΑΜΜΑΤΑ), HEART CHASER 1,2,3!, BARBOUTI!, STROOPIE!, AMSTABOO!
TEXT ADVENTURES:
BUDRUMI!, ART WAR!, BATTLE OF LENINGRAD!, RODOLFO SKYLARRIENTE 1,2,3!

pelrun

#1
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!

skylas

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!
Web: https://amstradsakis.blogspot.com
Twitter: https://twitter.com/AmstradSakis
My programs (only BASIC):
RETRO-LOADSHEET!, PENALTY KICKS!, CAPITAL QUIZ!, CAPITAL QUIZ 2! (Reverse edition), HEADS OR TAILS (ΚΟΡΩΝΑ/ΓΡΑΜΜΑΤΑ), HEART CHASER 1,2,3!, BARBOUTI!, STROOPIE!, AMSTABOO!
TEXT ADVENTURES:
BUDRUMI!, ART WAR!, BATTLE OF LENINGRAD!, RODOLFO SKYLARRIENTE 1,2,3!

Urusergi

#3
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

GUNHED

option = int(RND*3)



http://futureos.de --> Get the revolutionary FutureOS (Update: 2024.10.27)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

skylas

Many thx to all for your answers!!!
Web: https://amstradsakis.blogspot.com
Twitter: https://twitter.com/AmstradSakis
My programs (only BASIC):
RETRO-LOADSHEET!, PENALTY KICKS!, CAPITAL QUIZ!, CAPITAL QUIZ 2! (Reverse edition), HEADS OR TAILS (ΚΟΡΩΝΑ/ΓΡΑΜΜΑΤΑ), HEART CHASER 1,2,3!, BARBOUTI!, STROOPIE!, AMSTABOO!
TEXT ADVENTURES:
BUDRUMI!, ART WAR!, BATTLE OF LENINGRAD!, RODOLFO SKYLARRIENTE 1,2,3!

Urusergi

#6
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

Powered by SMFPacks Menu Editor Mod