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: 11386
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: 1409
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
Thierry
Martin Piper
daimansion
ΛΛdZ
Peacemaker/CENSOR/Hi..
The Human Co../Maste..
megasoftargentina
fugu/Excess
Guests online: 120
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 Tim  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.037 sec.