[Solved] use map checksum to seed some random spawning
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
[Solved] use map checksum to seed some random spawning
I have no idea how to do this. Can someone teach me how to use the map's checksum to seed some predictable random spawning? Say I want to scatter a random bunch of trees all over the map but it uses the map checksum as a seed so that the randomness is, uh, consistent (until the map is altered, I understand).
Last edited by Nash on Thu Feb 22, 2018 1:09 am, edited 1 time in total.
Re: [Request] use map checksum to seed some random spawning
If the problem is only in setting the seed then it can be done like this
Of course you can code more sophisticated string to 32-bit number conversion, for example CRC32.
Code: Select all
string checksum = level.GetChecksum();
int length = checksum.Length(); // should be always 32 for MD5 checksum
int seed = 0;
for (int i = 0; i < length; ++i)
{
seed ^= checksum.CharCodeAt(i) << 8 * (i % 4);
}
SetRandomSeed[my_random_sequence](seed);
for (int i = 0; i < 10; ++i)
{
double x = frandom[my_random_sequence](0, 1000.);
double y = frandom[my_random_sequence](0, 1000.);
console.printf("%f, %f", x, y);
}
Re: [Request] use map checksum to seed some random spawning
Thank you, this solution works perfectly for the purposes of randomly spawning things based on map checksum.
Now another question: will subsequent random/frandom calls after SetRandomSeed be seeded? I only want SetRandomSeed to affect this one function, and then I want every random/frandom call outside of that to revert to GZDoom's usual, unrpredictable randomness. Do I have to do anything special to achieve this?
Now another question: will subsequent random/frandom calls after SetRandomSeed be seeded? I only want SetRandomSeed to affect this one function, and then I want every random/frandom call outside of that to revert to GZDoom's usual, unrpredictable randomness. Do I have to do anything special to achieve this?
Re: [Request] use map checksum to seed some random spawning
Only numbers generated with my_random_sequence identifier are affected by seed value. So you need to make sure that name of random sequence identifier is unique.
Re: [Solved] use map checksum to seed some random spawning
Alright. Thanks _mental_ for simple and fast solution, :D