Attached is a listing that generates a random 10-digit ticket with each number from 0 to 9 inclusive in the sequence only once per run.
I wrote it to answer a code-golf question on Stack Exchange, with the ZX81 being an interesting beast as it's not very easy to golf on it (i.e., minimise and obfuscate the answers). I'm sure one of you guys could make it more golf-like. In fact, looking at it I could remove the GOSUB to increase the program speed a little; I could also change for FOR loop to could from 0 to 9.
Enjoy,
Shaun.
Random 10-digit generator
Random 10-digit generator
- Attachments
-
- zx81-ticket-generator.png (12.72 KiB) Viewed 5387 times
Re: Random 10-digit generator
May be faster! (don't use the recursive RND function! Only 10 loops)
1 LET A$="0123456789"
2 LET B$=""
3 LET R=INT(RND*LEN A$)+1
5 LET B$=B$+A$(R)
6 LET A$=A$( TO R-1)+A$(R+1 TO)
7 IF A$<>"" THEN GOTO 3
8 PRINT B$
9 STOP
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Re: Random 10-digit generator
Thanks for the tip, my amended answer did credit you here.
The listing is as follows (forgive the GOTO abuse... actually, don't):
Regards,
Shaun.
The listing is as follows (forgive the GOTO abuse... actually, don't):
Code: Select all
1 LET A$="0987654321"
2 LET R=INT (RND* LEN A$)+1
3 PRINT A$(R);
4 LET A$=A$( TO R-1)+A$(R+1 TO )
5 GOTO 2+((A$="")*4)
Shaun.
Re: Random 10-digit generator
Great answer Dr Beep.
The problem with Code Golf on the Stack Exchange is that it expects answers to be least typing, rather than actual fewest bytes because modern programming simply counts the number of characters in your script as how much memory it's taking.
Regards,
Shaun.
The problem with Code Golf on the Stack Exchange is that it expects answers to be least typing, rather than actual fewest bytes because modern programming simply counts the number of characters in your script as how much memory it's taking.
Regards,
Shaun.
- 1024MAK
- Posts: 5189
- Joined: Mon Sep 26, 2011 10:56 am
- Location: Looking forward to summer in Somerset, UK...
Re: Random 10-digit generator
So to the age old question: is PRINT one character (as stored internally), or five...
Mark
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor 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 being good this year.
ZX81 Chip Pin-outs
ZX81 Video Transistor 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 being good this year.