Hi,
I'm a computer programmer and am currently coding up an algorithm. As part of the algorithm I need to take a unique ID (either a series of characters or most likely a large integer) and generate an X,Y pair from this ID within a given square/rectangle (I know the co-ordinates of each 4 boundary coordinates of the square/rectangle). These generated X,Y coordinates need to be uniformly distributed within the area and also unique so that every time I do this conversion on a particular ID I always get the same resulting X,Y pair and a conversion on any other ID does not result in the same X,Y pair.
Can anyone help me with how to approach this?
Thanks in advance.
Hi CB,
Ok, I did this to a point by passing in a unique ID, seeding the random number generator, generating the two numbers and then scaling them (see below). The issue is that when I pass in the same ID again later I get two different numbers...This makes sense since this is what a random number generator is supposed to do in the first place but I suppose I'm a bit confused as to a way around it.
Thanks again.
if (GHLSrnGenCreated == OPC_FALSE)
{
ghls_randomGenPtr = prg_random_gen_create(intndID);
GHLSrnGenCreated = OPC_TRUE;
}
//variant in the range [0,1]
x = prg_random_double_gen(ghls_randomGenPtr);
y = prg_random_double_gen(ghls_randomGenPtr);
//x value:
hashedPosCoordinates->current_longitude = x * area_size_x;
//y value:
hashedPosCoordinates->current_latitude = y * area_size_y;
The whole purpose of a seed is to generate the same sequence of numbers when you repeat the process with the same seed. So there is something wrong with the seeding method, maybe you have to replicate the whole state vector of the prng, you will have to look at the documentation of the number generator to see what it is doing.