Random Number Seed

Started by Pix, September 16, 2019, 03:01:19 AM

Previous topic - Next topic

Pix

Is there any way to manually seed the built-in random number generator? I need to "randomly" create levels and be able to regenerate the same level again at a later time so I'd like to reseed to the same starting point each time I build the level.

Vectrex32

If you don't call Randomize() in your program, you will get the same sequence of numbers from Rand() every time you run. You could build your levels before you call Randomize() and when you're done with that, call Randomize() so that the game play will be random.

If you want to create a level after you've had random game play, there's no way to "undo" the effect of Randomize(). You would need to write your own pseudo-random number generator. Sorry.

But since you have so much memory available to you, is it feasible for you to generate all your levels at the beginning of the game and just keep them around?

- Bob



Pix

I don't think storing them all in RAM is an option unless memory allocation has changed in the firmware revisions since I wrote most of this. I was fighting memory issues right the way along with all the predefined arrays I'm using. I ended up pushing some of the graphics arrays out to separate files on the cart to be loaded on request to free up some room.

I'll create my own random number generator instead - it doesn't have to be anything too clever. I'm sure I can pinch an algorithm from somewhere.

Vectrex32

I made significant improvements to memory efficiency in version 1.17, but it was mostly in the compactness of compiled code.

- Bob