Page 1 of 1

Button press as random seed generator

Posted: Mon Oct 01, 2012 3:05 am
by rainwarrior
Here's a little test using the length of time you hold down the start button as a random seed. This could be suitable for a title screen where you press start to begin the game.

http://rainwarrior.ca/projects/nes/buttonlen.zip

I just enter a polling loop when start is held, incrementing it each time. When you release, the 8-bit loop counter is displayed on the screen. ca65 source is included if you want more details.

Actually works pretty well. On emulators I don't think you really get sub-frame timing on the input (I find the number 47 comes up a lot on FCEUX), but on the NES it seems completely random, and even on emulators it's not bad at all. Dwedit mentioned a possible need to debounce when doing this, but I don't seem to have any problem with that on my NES.


Fun fact: the GBA port of Final Fantasy IV seeds its random number generator by number of seconds spent on the title screen. I abused this at one point to finally get a pink tail. (My avatar is related.)

Re: Button press as random seed generator

Posted: Mon Oct 01, 2012 4:07 am
by Bregalad
Fun fact: the GBA port of Final Fantasy IV seeds its random number generator by number of seconds spent on the title screen. I abused this at one point to finally get a pink tail. (My avatar is related.)
Honnestly this is quite the natural way to do it.
I just call the random routine in the VBlank (and seed at '1' at reset), and by the time the user will start a new game, the time spent on the title screen is random therefore the RNG is actually random as well.

Re: Button press as random seed generator

Posted: Mon Oct 01, 2012 4:13 am
by rainwarrior
Counting frames is pretty normal, counting seconds not so much (and very easy to abuse!).

Re: Button press as random seed generator

Posted: Mon Oct 01, 2012 12:45 pm
by Bregalad
Well I think it's no secret that people behind GBA's ports of Final Fantasy games were a bunch of incompetents.

Re: Button press as random seed generator

Posted: Mon Oct 01, 2012 2:04 pm
by zzo38
You can also use microphone and initial contents of RAM, but they should not be used by themself because they might not always be available or working; but I suppose it could be used in combination with button press timing.