Neat one-liners

Chat about anything CX16 related that doesn't fit elsewhere
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: Neat one-liners

Post 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.
BruceRMcF
Posts: 224
Joined: Sat Jan 07, 2023 10:33 pm

Re: Neat one-liners

Post 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.
User avatar
desertfish
Posts: 1076
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Neat one-liners

Post 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.
Last edited by desertfish on Wed Aug 09, 2023 10:50 pm, edited 1 time in total.
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: Neat one-liners

Post 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.
EbonHawk
Posts: 17
Joined: Thu Mar 16, 2023 10:37 am

Re: Neat one-liners

Post by EbonHawk »

It causes it to start out more randomized, like the RND(1) suggestion that was given, that's all.
EbonHawk
Posts: 17
Joined: Thu Mar 16, 2023 10:37 am

Re: Neat one-liners

Post by EbonHawk »

These are really cool, btw.
mobluse
Posts: 172
Joined: Tue Aug 04, 2020 2:16 pm
Location: Lund, Sweden
Contact:

Re: Neat one-liners

Post 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.
Attachments
PETSCIICOLOR.BAS
(207 Bytes) Downloaded 323 times
X16&C64 Quiz: Try It Now! Huge Char Demo: Try It Now! DECPS: Try It Now! Aritm: Try It Now!
mobluse
Posts: 172
Joined: Tue Aug 04, 2020 2:16 pm
Location: Lund, Sweden
Contact:

Re: Neat one-liners

Post 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 3227 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)
X16&C64 Quiz: Try It Now! Huge Char Demo: Try It Now! DECPS: Try It Now! Aritm: Try It Now!
bleggett29
Posts: 14
Joined: Fri Jun 30, 2023 8:41 am

Re: Neat one-liners

Post 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.
mortarm
Posts: 281
Joined: Tue May 16, 2023 6:21 pm

Re: Neat one-liners

Post 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.
Post Reply