Silly Questions

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Silly Questions

Post 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
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Silly Questions

Post by 1024MAK »

A18D2E78-EB2F-4A11-AEEA-E3F9920D562E.jpeg
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Silly Questions

Post by Moggy »

Mine prints 5 which is 1 bigger than Mark's, therefore my listing is superior so best use my version. :ugeek:
Attachments
rnd.jpg
rnd.jpg (2.66 KiB) Viewed 1066 times
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Silly Questions

Post 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. :ugeek:
Well… what can I say to that! :lol:

Maybe give you a high-five :D

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Silly Questions

Post by Moggy »

Actually I cheated. I had to run it 10 times to get the bloody 5!! :lol:

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.)
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post 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?
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Silly Questions

Post 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.
User avatar
xubuntu
Posts: 84
Joined: Sat Jun 18, 2022 12:42 pm
Location: Athens, GR

Re: Silly Questions

Post by xubuntu »

Ok, I think I understood. Thank for the explanations. What about my main issue? why the code doesn't work at all ? :(
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: Silly Questions

Post 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
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Silly Questions

Post 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.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply