English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 27 August 2018, 18:12   #1
LeCaravage
Registered User
 
LeCaravage's Avatar
 
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.
LeCaravage is offline  
Old 27 August 2018, 18:23   #2
meynaf
son of 68k
 
meynaf's Avatar
 
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
meynaf is offline  
Old 27 August 2018, 18:23   #3
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Quote:
Originally Posted by LeCaravage View Post
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.
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.
Galahad/FLT is offline  
Old 27 August 2018, 18:39   #4
LeCaravage
Registered User
 
LeCaravage's Avatar
 
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
LeCaravage is offline  
Old 27 August 2018, 18:47   #5
meynaf
son of 68k
 
meynaf's Avatar
 
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+.
meynaf is offline  
Old 27 August 2018, 19:18   #6
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Quote:
Originally Posted by LeCaravage View Post
@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
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.
Galahad/FLT is offline  
Old 17 September 2018, 22:14   #7
Photon
Moderator
 
Photon's Avatar
 
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.
Photon is offline  
Old 18 September 2018, 15:32   #8
Leffmann
 
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.
Leffmann is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:34.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.08506 seconds with 15 queries