Random_set_seed confusion

Sourav

Member
As we can use randomise() function but what's the speciality of random_get_seed() ?

here i attach another link about random ssed ...

TsukaYuriko

☄️
Forum Staff
Moderator
randomize sets the seed to something. What determines what it's set to is not documented.
random_set_seed sets the seed to something you specify.
random_get_seed returns the current seed.

TheouAegis

Member
Let's say you make a auto generating room. It uses a random value to generate the room. You save that random value to a file, then you generate your room. so the next time you start up the game or the next time you go back to that room, you can regenerate the room exactly the same way by setting the seed to that saved value and then generating the room.

RefresherTowel

Member
A way to think of the random number generator is as a series of numbers (1, 5, 7, 3, 10, 8, 7, 7, etc). Whenever you call a random function, it picks a number from that list, then moves on to the next (starting at position 0). So the first time you call random, it'll pick 1 and generate an output based on the number 1. The next time you call random, it will pick 5 (since that's next in the list) and generate an output based on that and so on. The output isn't necessarily going to BE the number it picks, but it will be based off that number.

That string of numbers is what you could call your "seed" in a sense. If you stick with the same seed each time you start the game, the random numbers you get will be the same numbers in the same order, which means the random functions will return the same numbers in the same order as the previous time you booted the game. If you change the seed, it will be a different set of numbers, which means the random functions will return different numbers.

By using `randomise()` you are telling the computer to pick a new seed (or string of numbers) to use whenever a random function is called. By saving and/or setting the seed, you can "force" the computer to use particular series of numbers, which will generally mean the same output from the RNG. It's not really important if you are just wanting to generate random numbers, as the numbers will still be "random" regardless of if you are setting a seed or not. But in particular circumstances, you might want to be able to save and retrieve a particular seed to use (an example would be in Minecraft, you can "save" the starting state of any world by saving the seed, and loading a world from that seed will generate the same world again, rather than a new one).

Thank you all

Sourav

Member
A way to think of the random number generator is as a series of numbers (1, 5, 7, 3, 10, 8, 7, 7, etc). Whenever you call a random function, it picks a number from that list, then moves on to the next (starting at position 0). So the first time you call random, it'll pick 1 and generate an output based on the number 1. The next time you call random, it will pick 5 (since that's next in the list) and generate an output based on that and so on. The output isn't necessarily going to BE the number it picks, but it will be based off that number.

That string of numbers is what you could call your "seed" in a sense. If you stick with the same seed each time you start the game, the random numbers you get will be the same numbers in the same order, which means the random functions will return the same numbers in the same order as the previous time you booted the game. If you change the seed, it will be a different set of numbers, which means the random functions will return different numbers.

By using `randomise()` you are telling the computer to pick a new seed (or string of numbers) to use whenever a random function is called. By saving and/or setting the seed, you can "force" the computer to use particular series of numbers, which will generally mean the same output from the RNG. It's not really important if you are just wanting to generate random numbers, as the numbers will still be "random" regardless of if you are setting a seed or not. But in particular circumstances, you might want to be able to save and retrieve a particular seed to use (an example would be in Minecraft, you can "save" the starting state of any world by saving the seed, and loading a world from that seed will generate the same world again, rather than a new one).
Actually, I am trying to create a room where a rood will be generated randomly. every time after entering the room it will show a different path. but the starting point and ending point will be the same. can anyone help me with this type of work

RefresherTowel

Member
Don't worry about the seed. You're misunderstanding the post a little bit (and I simplified things a touch). When you're running a game in the GMS IDE, it always uses the same seed unless you call `randomise()`. However, the particular seed (let's call it seed 1) doesn't have anything to do with randomness between rooms or anything like that. Seed 1, when run will have a number of particular outcomes when you call random in room 1. If you then leave room 1 or reset room 1, the random calls will be different. You can simply call `randomise()` and it will always be completely random. That's why I said: "It's not really important if you are just wanting to generate random numbers" because setting or loading seeds or worrying about seeds at all isn't related to just simple random number generation. It's related to the overall lower-level architecture that random functions draw from. It won't affect whether things are "random" or not.

TheouAegis

Member
Actually, I am trying to create a room where a rood will be generated randomly. every time after entering the room it will show a different path. but the starting point and ending point will be the same. can anyone help me with this type of work
If the start and end points are all that matter, then you don't need to save the seed, you need to save the start and end points. If the entire path itself needs to be the same while the terrain around it changes, then you should set the seed and generate the path, then randomize the seed and generate the terrain.

As for generating a random path with two specific points, you could use a modified Wilson's algorithm.

TheouAegis

Member
Your path most likely would just be made up of tiles in the room. You would use Wilson's on a 2D array the size of the tile map in that room at the start of the room to generate the path. Then you would add road tiles or whatever based on the values in that array. You can then either discard the array or keep it around for whatever other uses you may have for it.

As for terrain, just check if the location of the tree/rock is off the path. A less natural-looking method would be to use that array you generated a path on to also generate terrain. For each cell in the array, if it doesn't have a path in it, choose a random terrain element to add to that cell, then place that terrain element in the room much like you put the path in the room. But like I said, this will look very unnatural. You could treat each cell as a 'sector' and go to town with terrain elements inside each individual sector. In any case, though, you are still just checking that there isn't a path there before putting the terrain down.

Sourav

Member
Thanks again . you are so helpful . best wishes