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


Forums > C64 Coding > Another Random Generator
2017-05-05 19:17
xIII

Registered: Nov 2008
Posts: 155
Another Random Generator

For my little game Modulot I used this random generator I found on Codebase64:


GetRandom:
ldx #0
lda random+1
sta temp2
lda random
asl
rol temp2
asl
rol temp2
clc
adc random
pha
lda temp2
adc random+1
sta random+1
pla
adc #$11
sta random
lda random+1
adc #$36
sta random+1
sta RANDOMNUMBERS_TABLE,x
inx
bne GetRandom+2
rts

Unfortunately I found out (too late) that this routine always generates the same table. What I wanted was a different table every time this routine is called.

How can I create a random table that is different every time ?
 
... 3 posts hidden. Click here to view all posts....
 
2017-05-05 20:17
xIII

Registered: Nov 2008
Posts: 155
thx Groepaz,

a) In my IRQ: inc VALUE

b) the first lda random+1 is replaced by lda VALUE

this seems to work as I want.
2017-05-05 20:20
Groepaz

Registered: Dec 2001
Posts: 8548
nooo thats not a good idea :). instead initialize random (and random+1) once with such counter value (cia1 timer will do fine)
2017-05-05 20:34
ZeSmasher

Registered: Feb 2003
Posts: 285
I wonder where's the difference between Groepaz's and my solution :) just keep "inc value" in the irq while you play and the level is as random as RND
2017-05-05 20:41
Groepaz

Registered: Dec 2001
Posts: 8548
look at the routine above. if you replace the first LDA random+1 by some LDA counter thing, the entire routine doesnt do anymore what its supposed to do - there wont be any feedback for the highbyte at all, breaking all the sequence properties.

rule of thumb: dont try to make your own PRNG - use an existing one that is proven to work. your own will most likely be (much) worse.
2017-05-05 21:15
ZeSmasher

Registered: Feb 2003
Posts: 285
sure. but you just need 1 byte to have 256 random levels, 2 bytes for 64K levels, etc, no need to build a table and waste 256 bytes. also a table containing sorted numbers or one filled with random numbers doesn't change anything when the byte is picked up randomly from it. a table could make sense if you want to avoid repeated levels in a gameplay, but a game without repeated levels is boring, because when you are playing the 255th level you perfectly know which level you'll play next :)
2017-05-05 21:17
xIII

Registered: Nov 2008
Posts: 155
lda $dc04
sta random
lda $dc05
sta random+1


before the routine above?
2017-05-05 21:44
Groepaz

Registered: Dec 2001
Posts: 8548
xIII: yes, exactly

and yes, building a table is pointless - with a given seed the generator produces the same sequence anyway.
2017-05-06 08:23
xIII

Registered: Nov 2008
Posts: 155
Quote: sure. but you just need 1 byte to have 256 random levels, 2 bytes for 64K levels, etc, no need to build a table and waste 256 bytes. also a table containing sorted numbers or one filled with random numbers doesn't change anything when the byte is picked up randomly from it. a table could make sense if you want to avoid repeated levels in a gameplay, but a game without repeated levels is boring, because when you are playing the 255th level you perfectly know which level you'll play next :)

I agree on the levels (or patterns as I call them here).
The table is used to generate a 256 byte table of numbers (0 - 9) so that when the same pattern occurs, the numbers are not the same.
As it is now, I also use it to pick a random pattern.
   jsr random ; get random in range 0-ff
   tax
   lda random_table,x ; random table with 0-9
   sta pattern

but in v2 that will change to repeated levels ;)
2017-05-06 08:50
ZeSmasher

Registered: Feb 2003
Posts: 285
great about v2. don't forget to credit mr.Groepaz and me in it! :P
2017-05-07 21:52
Rudi

Registered: May 2010
Posts: 101
maybe you can read rasterpos from menu-timer.

there exists transform functions too.
if you allreedy have random 256-byte table loaded from disk, you can transform them numbers with a function using timer as input for each game level. but use a tranform that does keep all numbers intact, so they dont loose connectivity!
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
Rob/Papposoft
Mike
E$G/I-IokutO ForcE
pcollins/Excess
Snabel
Guests online: 28
Top Demos
1 Uncensored  (9.7)
2 Comaland 100%  (9.7)
3 Edge of Disgrace  (9.7)
4 Coma Light 13  (9.6)
5 The Shores of Reflec..  (9.6)
6 Wonderland XII  (9.6)
7 We Come in Peace  (9.6)
8 Lunatico  (9.6)
9 Incoherent Nightmare  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 Daah, Those Acid Pil..  (9.6)
2 Arok 20 Invitation  (9.5)
3 FMX Music Demo  (9.5)
4 Pandemoniac Part 2 o..  (9.5)
5 Dawnfall V1.1  (9.5)
6 Treu Love [reu]  (9.5)
7 Merry Xmas 2017  (9.4)
8 In Memoriam BHF  (9.4)
9 Dawnfall  (9.4)
10 Synthesis  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.4)
5 Crest  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Horizon  (9.8)
3 The Mind Slayer  (9.7)
4 The Shadow  (9.7)
5 Stormbringer  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.061 sec.