Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Pseudo-random number generator, set complete?
2011-11-28 01:00
Style

Registered: Jun 2004
Posts: 498
Pseudo-random number generator, set complete?

Hi all

Im looking for an algorithm that will generate random-looking numbers from 1 - 1000, but will only ever select any one number once. Obviously this is for the 64 screen :)

I seem to recall set complete pseudo-random algorithms at uni but cant recall much more. Any advice?

thanks
 
... 10 posts hidden. Click here to view all posts....
 
2011-11-29 01:41
Style

Registered: Jun 2004
Posts: 498
Thanks for mentioning LFSR krill. Id never come across them before, but that's exactly what I need. And yep, that looks like what Groep's routine is doing - of course, Ill have to write my own, otherwise Ill have to credit Groep :)
2011-11-29 01:45
chatGPZ

Registered: Dec 2001
Posts: 11523
hihi... this routine isnt mine either... or well, the algo isnt :)
2011-11-29 02:07
Style

Registered: Jun 2004
Posts: 498
pfffft...... dirty ripper

:)
2011-12-15 07:00
ChristopherJam

Registered: Aug 2004
Posts: 1424
or, could use the old linear congruential. Here's x=(x*261+117)%1024:

genRand
; perform rand'=(rand*261+117)%1024
	lda rand
	asl
	rol t4hi   ; don't need to init t4hi, as only using bottom two bits
	asl
	rol t4hi
	clc
	adc rand
	sta rand
	lda t4hi
	adc rand+1   ;a::rand' is now rand*5
	clc
	adc rand     ;(a::rand')%1024 is now (rand*261)%1024
	sta rand+1

	clc
	lda rand
	adc#117
	sta rand
	lda rand+1
	adc#0
	and#3
	sta rand+1
	rts

rand
	lda#0
t4hi
	brk

(cf http://en.wikipedia.org/wiki/Linear_congruential_generator . The 117's an arbitrary odd number, and the multiplier must be one more than a multiple of four )
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Frostbyte/Artline De..
bOOZElEE
Stack J./Triumwyrat,..
Rhythm/G★P
Sychamis
stephan-a
Slaxx/Q/HF/MYD!
Guests online: 138
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.6)
5 Coma Light 13  (9.6)
6 Edge of Disgrace  (9.6)
7 Signal Carnival  (9.6)
8 Wonderland XIV  (9.5)
9 Uncensored  (9.5)
10 Comaland 100%  (9.5)
Top onefile Demos
1 Nine  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.5)
6 Scan and Spin  (9.5)
7 Onscreen 5k  (9.5)
8 Grey  (9.5)
9 Dawnfall V1.1  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Artline Designs  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Performers  (9.3)
5 Censor Design  (9.3)
Top Graphicians
1 Mirage  (9.7)
2 Archmage  (9.7)
3 Sulevi  (9.6)
4 Pal  (9.6)
5 Hein  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.046 sec.