Page 1 of 2
Silly Questions
Posted: Sat Mar 18, 2023 1:31 pm
by xubuntu
I have some silly question concerning basic,
why that code doesn't return any results ?
10 LET E=INT(RND*5)+1
15 PRINT E
Re: Silly Questions
Posted: Sat Mar 18, 2023 2:04 pm
by 1024MAK
Re: Silly Questions
Posted: Sat Mar 18, 2023 2:57 pm
by Moggy
Mine prints 5 which is 1 bigger than Mark's, therefore my listing is superior so best use my version.
Re: Silly Questions
Posted: Sat Mar 18, 2023 3:05 pm
by 1024MAK
Moggy wrote: ↑Sat Mar 18, 2023 2:57 pm
Mine prints 5 which is 1 bigger than Mark's, therefore my listing is superior so best use my version.
Well… what can I say to that!
Maybe give you a high-five
Mark
Re: Silly Questions
Posted: Sat Mar 18, 2023 3:10 pm
by Moggy
Actually I cheated. I had to run it 10 times to get the bloody 5!!
Also your last line number is 15 mine is 20 which does have an effect on the RND generator!!
(Apologies I'm in a flippant mood.)
Re: Silly Questions
Posted: Sat Mar 18, 2023 3:33 pm
by xubuntu
Very nice!
I choose Moggy's version. His simplicity is unpararel.
Another question:
I don't want RECURRING events. I don't want an EVENT to be same on next turn, and if it's the same, get a new random "EVENT" variable.
But for some reason this isn't working
Code: Select all
450 LET REPEAT=0
500 RAND
510 LET EVENT=INT (RND*2)+1
515 IF REPEAT=EVENT GOTO 500
#THE 1ST TIME OBVIOUSLY REPEAT CANT BE EQUAL TO EVENT AS IT IS SET TO 0
517 LET REPEAT=EVENT
520 IF EVENT=1 THEN PRINT EVENT
530 IF EVENT=2 THEN PRINT EVENT
540 IF EVENT=3 THEN PRINT EVENT
580 GOTO 500
I just don't want the same number to come up TWICE in a row.
ps. (hidden sneaky question) Does rand do anything there? Does it indeed cause a randomization?
Re: Silly Questions
Posted: Sat Mar 18, 2023 4:15 pm
by Moggy
RAND X, will start the sequence of random numbers at a fixed point in a sequence of 65536 numbers and will be the same every time for a given value of X, whereas RAND 0 or without the 0 will start the sequence at a point determined by how long the TV has been switched on.
Taken from the ZX81 manual, it gives a fuller explanation of both RND and RAND.
RND & RAND: These are both on the same key, but whereas RND is a function, RAND is a keyword, like PRINT. RAND is used for controlling the randomness of RND.
RND is not truly random, but follows a fixed sequence of 65536 numbers that happen to be so jumbled up as to appear random (RND is pseudo-random). You can use RAND to start RND off at a definite place in this sequence by typing RAND, & then a number between 1 & 65535, & then NEWLINE. It's not so important to know where a given number starts RND off, as that the same number after RAND will always start RND off at the same place. For instance, type
RAND 1 (& NEWLINE)
& then
PRINT RND
& type both these in turn several times. (Remember to use FUNCTION to get RND.) The answer from RND will always be 0.0022735596, not a very random sequence.
RAND 0
(or you can miss out the 0) acts slightly differently: it judges where to start RND off by how long the television has been on, & this should be genuinely random.
Re: Silly Questions
Posted: Sat Mar 18, 2023 4:43 pm
by xubuntu
Ok, I think I understood. Thank for the explanations. What about my main issue? why the code doesn't work at all ?
Re: Silly Questions
Posted: Sat Mar 18, 2023 5:06 pm
by Moggy
Programming is not my strong point however the program pictured in this thread may give you some ideas..
https://www.sinclairzxworld.com/viewtopic.php?t=2236
Re: Silly Questions
Posted: Sat Mar 18, 2023 9:18 pm
by XavSnap
why the code doesn't work at all ?
LET RND=0
PRINT RND
0
PRINT RND*5
0
Right?
Use the function "Shift+NewLine"+"T" key.
515 IF REPEAT=EVENT GOTO 500
"Then"
540 IF EVENT=3 THEN PRINT EVENT
INT(RND*2)+1 can't be upper than 2 !
0>RND>.9999999
RND*2>> 0=>1.9999 (INT=0 and 1)
int(RND*2)+1= 1 or 2.