Home > Back-end >  How to generate a lot of don't repeat the integer 3 d coordinate, turn to for help
How to generate a lot of don't repeat the integer 3 d coordinate, turn to for help

Time:09-24

How to generate a lot of don't repeat the integer 3 d coordinate, turn to for help, strives for the big help, urgent need

CodePudding user response:

Domain have how old?
Using a hash method to record the value,
Hash key can be spliced integer, when your domain is less, not more than 21, can use (x<42) + (y<21) + z as key
When the domain is very big, can use a structure

Struct tag_coord {
int x;
int y;
Int z;
} coord.
Store coordinates, and then use unsigned char * p=& amp; Coord. Visit each byte, we replace for string hash table, with numerical will slowly, like printf
String bin2str [256]={" 00 ", "01",... , "FF"};
The string key;
for (int i=0; i{
The key +=bin2str [p] [I];
}

CodePudding user response:

After generating random coordinates, in a

STD: : unorded_set,

Each judge did exist in the set this hash, so that repeated, if not, OK

CodePudding user response:

How can refer to a 24-bit true color, it is three Numbers, color space, each value of the range is 0-255
If the value range is larger than the office, with 16 32-bit 64,
How to produce don't repeat? And can easy access to the random three-dimensional coordinates? The easiest way is to "an attack on dimension reduction", the three dimensional space dimension reduction into one dimension,
Is three values zyx, let x began to increase, from 0 to the maximum after x zero, y plus one and so on, all of the values listed, produce a linear one-dimensional coordinate space, if want to random access to coordinate values, use a random number to get the coordinates of a 3 d space,

CodePudding user response:


Only have a list of storage and query whether repeated,

CodePudding user response:

If there is no special requirement, you can order it is ok to:
,1,2,1,1 [1], [1], [1, 2, 1], [2,1,1],,1,3 [1],...
  • Related