Page 2 of 2

Re: Neat one-liners

Posted: Sat Jan 21, 2023 7:45 pm
by grml
desertfish wrote: Sat Jan 21, 2023 2:45 pm I made it into a one liner but you can no longer copy paste it from the forum because of the embedded control characters that you have to type now ;)
I checked the emulator source code and learned you can do this:

Code: Select all

CLS:LOCATE30,40:FORI=0TO9^9:COLORRND(1)*16:?"\XD1\X9D"MID$("\X91\X11\X9D\X1D",1+RND(1)*4,1);:NEXT
BruceRMcF wrote: Sat Jan 21, 2023 5:12 pm Does anything interesting happen with RND(T) in one of the RND() functions ... that is, using a different seed each time through the loop?
Frequent reseeding usually just results in boring, easily predictable numbers.

Re: Neat one-liners

Posted: Sun Jan 22, 2023 3:16 pm
by BruceRMcF
grml wrote: Sat Jan 21, 2023 7:45 pm
BruceRMcF wrote: Sat Jan 21, 2023 5:12 pm Does anything interesting happen with RND(T) in one of the RND() functions ... that is, using a different seed each time through the loop?
Frequent reseeding usually just results in boring, easily predictable numbers.
Oh, wait, it's been a long time since I've used CBM2.0 RND. If a RTC is running in the X16 (in the C64 the clock had to be started up, and it was only close to "Real Time" if you set it close to real time), wouldn't RND(0) outside the loop and RND(1) inside the loop start you with a variety of starting spots based on where the low order integer of the system timer is when that is read for the RND(0) seed?

AFAIR, the problem with calling RND(0) repeatedly is the timer seed only has a range of 0-59. So it's better used to initialize the pseudo-random number generator and then read down the sequence by calling RND with a positive seed.

Since RND(0) reseeds every time and RND(1) moves 1 step down the pseudorandom number sequence, the idea of a "RND(I) ... RND(1)" pattern versus the "RND(1) ... RND(1)" pattern is that if you happen to land at the same spot in the pseudo-random number sequence but in a different iteration of the loop, that part of the pattern won't repeat.

Re: Neat one-liners

Posted: Fri Mar 10, 2023 4:53 pm
by desertfish
Here's another neat one, courtesy of 8 Bit Show And Tell:


0COl0,12:FoI=1TO80:B=B=(I=1):?Ch(18-B*128)Mi("\X9B\XA9\X97\XDF",RND(.)*4OR1,2);:Ne:Go0

copy-paste this into the emulator. you have to type RUN afterwards.

Re: Neat one-liners

Posted: Fri Mar 10, 2023 5:50 pm
by grml
That IS neat indeed, especially how it tricks your eyes into seeing "depth"

I have the utmost respect for people who have the patience to watch 50 minutes of this just for the one line of code.

Re: Neat one-liners

Posted: Sat Apr 15, 2023 11:20 pm
by EbonHawk
It causes it to start out more randomized, like the RND(1) suggestion that was given, that's all.

Re: Neat one-liners

Posted: Sat Apr 15, 2023 11:30 pm
by EbonHawk
These are really cool, btw.

Re: Neat one-liners

Posted: Tue Jun 27, 2023 5:07 pm
by mobluse
This can be pasted into the emulator (R43) and press Enter:

Code: Select all

Sc12*Rn(1):FoO=0TO1STe0:COl16*Rn(1),16*Rn(1):?Ch(96*Rn(1)+160);:Ne
Expanded this is, but this doesn't fit in the input buffer:

Code: Select all

SCREEN12*RND(1):FORO=0TO1STEP0:COLOR16*RND(1),16*RND(1):PRINTCHR$(96*RND(1)+160);:NEXT
Try It Now!
The full X16 BASICv2 program waits 5 s before starting, but you can press Ctrl+C and go up to the one-liner and press Enter to run it in an alternative way. You can test Shift+Alt a couple of times while you run it to see more characters.

Re: Neat one-liners

Posted: Wed Jun 28, 2023 11:26 am
by mobluse
This game, called Guess My Border Color, can be pasted into the emulator (R43), then press Enter:

Code: Select all

Sc7:A=INT(256*Rn(1)):Po$9F2C,A:FoO=0TO9^9:LINPUTG$:G=Va(G$):IFG<>ATh?Sg(A-G):Ne
You enter guesses of the border color between 0 and 255 in decimal. It replies -1 if the answer is lower, and 1 if the answer is higher, and quits if you guess right. Paste again for a new round. It is considered a win if you guess correctly before it begins to scroll.
Guess My Border Color by mobluse
Guess My Border Color by mobluse
2023-06-28-125559_640x480_scrot.png (13.21 KiB) Viewed 3279 times
The expanded code is:

Code: Select all

SCREEN7:A=INT(256*RND(1)):POKE$9F2C,A:FORO=0TO9↑9:LINPUTG$:G=VAL(G$):IFG<>ATHENPRINTSGN(A-G):NEXT
but that doesn't fit in the input buffer.

If you paste this once in a session before pasting the oneliner you get a more random border color:

Code: Select all

?RND(-TI)

Re: Neat one-liners

Posted: Sun Jul 23, 2023 5:20 pm
by bleggett29
Make sure the RTC is set and started before running code.

Code: Select all

0 PRINT TI$"\X91" : GOTO.
or

Code: Select all

0 PRINT DA$"\X1D"TI$"\X91" : GOTO.

Re: Neat one-liners

Posted: Sun Jul 30, 2023 6:52 pm
by mortarm
grml wrote: Sat Jan 21, 2023 10:00 am This one is interesting. If you watch it go for a minute, you can see the pattern go through a bunch of distinctive phases while the RNG "warms up", until it finally seems to generate more uniformly distributed numbers.
Run it using different SCREEN values. You get some interesting effects.