Vectrex32

General Category => General Discussion => Topic started by: Pix on September 16, 2019, 03:01:19 AM

Title: Random Number Seed
Post by: Pix on September 16, 2019, 03:01:19 AM
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.
Title: Re: Random Number Seed
Post by: Vectrex32 on September 16, 2019, 08:30:59 AM
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


Title: Re: Random Number Seed
Post by: Pix on September 16, 2019, 11:56:37 AM
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.
Title: Re: Random Number Seed
Post by: Vectrex32 on September 16, 2019, 12:38:41 PM
I made significant improvements to memory efficiency in version 1.17, but it was mostly in the compactness of compiled code.

- Bob