It is currently Mon Oct 20, 2014 5:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Jun 29, 2011 10:18 am 
Online
User avatar
 Profile

Joined: Sat Mar 26, 2011 3:01 pm
Posts: 263
Location: Kings Langley
This is about the fastest random number generator you can get although it is really just a sequence of 256 numbers using 14 bytes (code and data if seed is in ZP)

An .ssd is attached and you can see the description here http://www.retrosoftware.co.uk/wiki/index.php/Random_number_generator_%28very_fast_-_very_basic%29

Code:
L.
   10*K.10O.|MREN.|M*FX12 4|ML.|M
   20FOR O = 0 TO 2 STEP 2
   30seed = &70
   80P%=&5200
   90[
  100OPT O
  110.rand
  120LDA seed
  130ASL A
  140ASL A
  150CLC
  160ADC seed
  170CLC
  180ADC #&45
  190STA seed
  200RTS
  210]
  220NEXT
  230FOR N = 0 TO 255
  240CALL rand
  250PRINT " ";~?seed;
  260NEXT


Attachments:
File comment: rand BBC test program .ssd
rand.zip [686 Bytes]
Downloaded 14 times
Top
 
PostPosted: Wed Jun 29, 2011 4:42 pm 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 6:46 pm
Posts: 380
Location: Málaga, Spain
That's actually a pretty good algorithm. If you weren't worried about reproducibility, you could EOR with a timer at the end, e.g. EOR &FE44, which should add a bit more randomness!


Top
 
PostPosted: Wed Jun 29, 2011 4:56 pm 
Online
User avatar
 Profile

Joined: Sat Mar 26, 2011 3:01 pm
Posts: 263
Location: Kings Langley
I was tempted to self mod the addition every time the seed gets to 0 to chain many different sequences but the timer is definitely in the spirit of this code.


Top
 
PostPosted: Thu Jun 30, 2011 1:07 pm 
Online
User avatar
 Profile

Joined: Sat Mar 26, 2011 3:01 pm
Posts: 263
Location: Kings Langley
As a little side note to newer programmers, it is very useful to keep separate random numbers for game/sound/graphics/etc (especially in multi-machine synchronised state games) to aid in debugging and at the cost of a few bytes, well worth it.

When debugging, I would recommend not using Rich's excellent tip (of EORing with the timer low-byte) or NOPping it out in a binary to make bug reproduction easier.


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: