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.)
Button press as random seed generator
Moderator: Moderators
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Button press as random seed generator
Honnestly this is quite the natural way to do it.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.)
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.
- rainwarrior
- Posts: 8759
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Button press as random seed generator
Counting frames is pretty normal, counting seconds not so much (and very easy to abuse!).
Re: Button press as random seed generator
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
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.
(Free Hero Mesh - FOSS puzzle game engine)