Page 1 of 1

Level seed

Posted: Fri Jun 27, 2008 2:45 pm
by Alan
Simply a number you can set in the level properties that is the seed for the random number. If set to the default 0 then it uses the normal RnDs random method (using milliseconds to get a "real" random number, I guess), otherwise use a seed.

RnDs random elements would react the same every time (like watching a tape), E.G. Setting a seed of 32511 will make a certain yamyam always move down at the start of a level, setting it to 33 will make it go left. In VB I call this "hand picked random".

Good for getting some strict rules in a level (for timing stuff maybe). I'd use it for CEs personally...in fact the amount of cool things you could make with this very simple setting is huge!

It is would also be very cool for BD type levels, where a box of boulders and dirt are drawn randomly in the cave, but with the seed set they always appear in the same place......to make the cave harder you "hand pick" another seed until the boulders are in a more tricky position. This is really the skill level in BD.

Setting the seed in a CE action would also be very nice....you could construct the interior of house randomly (think Zelda),and change the seed as you enter it. Furniture is randomly placed, but using the seed so it looks the same every time you enter (the seed would be determined by the map position, as well as the house number)

Coding would be easy, if C+ has similar seed functions as VB......

Code: Select all

Rnd (-1)
Randomize 2442

For L = 1 To 5
    Print Int(Rnd(1) * 100)
Next
If you run this in VB, using the seed of 2442 will always print 63,51,17,25,2 (try it if you have VB6). Taking out the first two lines returns the randomness to normal (I use "Randomize Timer" to get real random), so really the RnDs element code wouldn't have to be changed, just the random initialise.

Posted: Sat Jun 28, 2008 1:27 am
by Davacardo
You're right, it does!
However, if you remove the first two lines (Rnd (-1) and Randomize 2442), shouldn't it end up generating the same numbers every time? You need to include randomize before rnd to generate random numbers, or other wise the same numbers will be generated every time the program starts.

Let's see if I can remember from university.
To make random nubmers in C++:

Code: Select all

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
     srand(time(0));
     cout << rand() % X << endl;
     system(pause);
     return 0;
}
That should display a random number between 0 and X. I think - I wasn't actually taught this, so I don't know - if you replace "time(0)" with a number, it will have the same seed each time.

The problem is apparently RnD is actually coded in C.

Posted: Sat Jun 28, 2008 1:14 pm
by Alan
However, if you remove the first two lines (Rnd (-1) and Randomize 2442), shouldn't it end up generating the same numbers every time?
Hummm, yeah I know....VB's default random is already seeded....but that wouldn't of been a good example would it? ;-)

Forget about the internals, typos, and VB's problems........what about the idea?

Posted: Mon Jun 30, 2008 4:15 pm
by Holger
This seems to be a very good idea -- very simple on the first view (and probably also very simple to implement), but apparently very powerful and with a high potential for building random-based levels (especially in conjunction with a corresponding CE action like "set level seed")!

I think I should just make a test version with such a feature and provide a test binary to check if it works as desired!

Posted: Mon Jun 30, 2008 7:19 pm
by Alan
Cool, I hope it works!

Actually, I made this level not long ago (random is in my mind a lot recently ;-) ). It simply prints out a random readable word when the level starts. Obviously nonsense words, but you can sound them out (cadence?)

Much better for you than looking at random numbers or randomly placed items. (and no, it can't make swear words!)

http://ambience.artsoft.org/random_word.zip

You could use this to give your random cave a random name, perhaps...