Page 1 of 1

Random 10-digit generator

Posted: Thu Feb 16, 2017 5:19 pm
by Shaun_B
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.

Re: Random 10-digit generator

Posted: Thu Feb 16, 2017 8:24 pm
by XavSnap
:D

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

Re: Random 10-digit generator

Posted: Fri Feb 17, 2017 10:42 pm
by Shaun_B
Thanks for the tip, my amended answer did credit you here.

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)
Regards,

Shaun.

Re: Random 10-digit generator

Posted: Fri Feb 17, 2017 11:34 pm
by XavSnap
Cool !
:D

Re: Random 10-digit generator

Posted: Tue Jul 11, 2017 9:54 pm
by dr beep
IMG_4887.PNG
(94.58 KiB) Downloaded 464 times

Re: Random 10-digit generator

Posted: Tue Jul 18, 2017 9:52 am
by Shaun_B
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.

Re: Random 10-digit generator

Posted: Tue Jul 18, 2017 5:24 pm
by 1024MAK
So to the age old question: is PRINT one character (as stored internally), or five...

Mark