This is related to C#/Unity, but it boils down to simple math/loops/shifts.
Here is the basic idea of the random functions I have:
public float GetRand(int seed, int x, int y) {
return (float)(new Random(seed + x + (y <<16)).NextDouble();
}
public int GetRand(int seed, int x, int y, int range) {
return (new Random(seed + x + (y <<16)).Next(range);
}
The problem is that when the client side starts, its calling both these functions about a million times (1024x1024 tile buffer), which means that I generate 1,048,576 new random objects that are immediately discarded.
I'm using this to determine the height and tile type of each tile on a game map. The server and the client will need to know the same information, but from the map sizes, that is easily 50 megs of data. Instead of transferring this data from server to client, and requiring the server to maintain this data for every user, when I need to know a tile height/position, I simply rely on this.
The client needs to do this in bulk, to preload an area of the map. The server is a restful API, and usually doesn't care about specific terrain. but when it does, I simply have it request a rectangle of the height map or a region of the tile type map, which is generated on the fly by these functions.
What I would like, is to reduce the function down to a smaller math example to get a pseudo random value instead of producing/depending on new random objects.
So far, my existing functions work, and the speed is not bad on client or server, but it seems like an area that could get a quick boost in speed, and I'll need that as I add more features.