27 August 2018, 18:12 | #1 |
Registered User
Join Date: May 2017
Location: AmigaLand
Posts: 459
|
[ASM] Random number generator
Hi there,
I'm trying to code a fast random number generator. I'm not able to find a good seed generator. May be using the CIA timers ? But I don't find any example how to grab a byte (or .W) from the timer registers ? Any help would be grateful. |
27 August 2018, 18:23 | #2 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Here's some code i'm using (but i do this every time i generate a number, not just for seeding) :
Code:
move.w $dff006,d0 swap d0 move.b $bfe801,d0 lsl.w #8,d0 move.b $bfd800,d0 |
27 August 2018, 18:23 | #3 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
A lot of people grab the contents of the VHPOSR register ($DFF006) for their "random" seed to start off with, nothing complicated in grabbing that at all.
|
27 August 2018, 18:39 | #4 |
Registered User
Join Date: May 2017
Location: AmigaLand
Posts: 459
|
@all : Thanks guys for you help.
I was also using $dff006 as a seed but in my "probably crappy" routine the period of generated numbers is short. I think I will stole the meynaf routine |
27 August 2018, 18:47 | #5 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Feel free to use it
I have more advanced code, but that's for 68020+. |
27 August 2018, 19:18 | #6 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
Just make sure you do it right at the start of your code, and before you do any vertical blank waiting, that way you'll get a more "random" seed.
|
17 September 2018, 22:14 | #7 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
|
Note that when you use the timers, your code may be running so fast that the value doesn't have time to change (accelerators). And if you solve it by running them once a frame, obviously it won't be random either.
You can test the output by putting it in chipram as a sample and play it. If it sounds like white noise, it's usually random enough. |
18 September 2018, 15:32 | #8 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
It's a bit of a problem to get a truly random seed on the Amiga.
Because task switching is often done pre-emptively at the vertical blanking, reading the vertical counter might give you the same value you got last run. Same thing with some of the timers or TOD clocks, at least one of them seems to reset at each vertical blank. I think the best way would be to collect as many semi-random values you can find, vertical counters, mouse counters, Kickstart checksum, system date, etc. and then compute a simple 32- or 64-bit hash from all of those and use that as your seed. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tool to convert asm to gnu asm (gas) | Asman | Coders. Asm / Hardware | 13 | 30 December 2020 11:57 |
Blitz Seed Random Number Generator | Ze Emulatron | Coders. Blitz Basic | 3 | 26 November 2017 11:08 |
asm code for a simple random generator | jotd | Coders. Asm / Hardware | 7 | 15 September 2017 09:14 |
random number generation (in asm) | meynaf | Coders. General | 183 | 29 November 2010 19:48 |
Help needed!!Random octal numbers generator(asm) | sheryn88 | Coders. General | 6 | 01 August 2010 07:19 |
|
|