Level seed

Got a cool idea that should be in R'n'D? Let's hear it!

Moderators: Zomis, Flumminator

Alan
Posts: 661
Joined: Fri Jun 18, 2004 7:48 pm

Level seed

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.

Davacardo
Posts: 89
Joined: Sun Jul 22, 2007 10:36 am
Location: Australia
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.

Alan
Posts: 661
Joined: Fri Jun 18, 2004 7:48 pm
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?

Holger
Posts: 3346
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:
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!

Alan
Posts: 661
Joined: Fri Jun 18, 2004 7:48 pm
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...