Fun with CBM arithmetics, Part III

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Fun with CBM arithmetics, Part III

Post by Mike »

Hi!

Just type in this small program and look how it wrecks havoc with the built-in random number generator of CBM BASIC:

Code: Select all

1 A=2087*794531
2 B=32768*65536
3 X=A/B:Y=RND(-X)
4 PRINTRND(1):GOTO4
P.S. https://xkcd.com/221/
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Fun with CBM arithmetics, Part III

Post by chysn »

Woah!

+1 for XKCD

The thing I envy most about the C64 isn't the sound or the sprites or the extra colors. It's the analog noise source in the SID that can act as a reliably-random random number generator. VIC-20's RND is so slow when you need to get a lot of random numbers, like to generate a maze. I've tried linear shift register techniques with limited success.

This only serves to deepen my despair.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Kweepa
Vic 20 Scientist
Posts: 1315
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: Fun with CBM arithmetics, Part III

Post by Kweepa »

But LFSR/LCGs are so easy!
There are a number of threads on denial about cheap, well behaved random numbers.

http://sleepingelephant.com/ipw-web/bul ... f=2&t=2304
http://sleepingelephant.com/ipw-web/bul ... f=2&t=2348

Sprites are the one thing I would take out of your list.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Fun with CBM arithmetics, Part III

Post by chysn »

Ah! You know where I've been going wrong with shift registers? I've been manipulating, then shifting, and then using the resulting bytes instead of a single bit at a time. Now that I try it as a source of bits, it makes all the difference in the world. Thanks! And that was your code, Mike, so thanks to you, too!

Okay, I'm changing my answer. Sprites are awesome, but I'll take the SID. Which really may not be a change after all.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Fun with CBM arithmetics, Part III

Post by Mike »

Some time ago (also @Kweepa) I posted a viable alternative to the built-in RND() function which is based on the QDRand generator published in Numerical Recipes:

Making a random number in Assembly

A bit further down the page, there's a demo program which puts the routine into the USR() function.

...

I found the behaviour of the original RND() function to be suspect already since 2006 (link), where I demonstrated that most of the seeds result in periods of just ~58000 different numbers, even though the seed size would suggest a period of at least 2^32 numbers. Later, I found a seed number that resulted in an even shorter period, just ~700 different numbers.

I then set out to find a possible fixpoint of the generator, and the OP shows the result.
groepaz
Vic 20 Scientist
Posts: 1187
Joined: Wed Aug 25, 2010 5:30 pm

Re: Fun with CBM arithmetics, Part III

Post by groepaz »

The thing I envy most about the C64 isn't the sound or the sprites or the extra colors. It's the analog noise source in the SID that can act as a reliably-random random number generator.
there is no such thing in the SID - it's a LFSR :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Fun with CBM arithmetics, Part III

Post by chysn »

groepaz wrote: Sat Jun 13, 2020 8:54 am
The thing I envy most about the C64 isn't the sound or the sprites or the extra colors. It's the analog noise source in the SID that can act as a reliably-random random number generator.
there is no such thing in the SID - it's a LFSR :)
Learn something new every day!
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
Post Reply