Skip to main content
added 209 characters in body
Source Link
le_m
  • 20.4k
  • 10
  • 70
  • 78

Is there truncation of some kind of going on, which trims the string and makes it more likely to get duplicates?

Yes, simply by rounding a random number, you cut off the fractional digits. This reduces the number of possible outcomes compared to the non-rounded random number.

In addition to that, you concatenate a timestamp (13 digits) with a value between 0 and 1000000 (1 to 7 digits). So your concatenated result will have a total number of 14 to 20 digits, but JavaScript's number datatype is of limited precision and represents integers faithfully up to about 16 digits only (Number.MAX_SAFE_INTEGERsee Number.MAX_SAFE_INTEGER).

Example: Let's assume the timestamp is 1516388144210 and you append random numbers from 500000 to 500400:

+'1516388144210500000' == 1516388144210500000 +'1516388144210500100' == 1516388144210500000 +'1516388144210500200' == 1516388144210500000 +'1516388144210500300' == 1516388144210500400 +'1516388144210500400' == 1516388144210500400 

You can see that, when converting those strings to numbers, they get rounded to the nearest available IEEE-754 double-precision (64 bit) number. This is because 1516388144210500000 > Number.MAX_SAFE_INTEGER.

Is there truncation of some kind of going on, which trims the string and makes it more likely to get duplicates?

Yes, you concatenate a timestamp (13 digits) with a value between 0 and 1000000 (1 to 7 digits). So your concatenated result will have a total number of 14 to 20 digits, but JavaScript's number datatype is of limited precision and represents integers faithfully up to about 16 digits (Number.MAX_SAFE_INTEGER).

Example: Let's assume the timestamp is 1516388144210 and you append random numbers from 500000 to 500400:

+'1516388144210500000' == 1516388144210500000 +'1516388144210500100' == 1516388144210500000 +'1516388144210500200' == 1516388144210500000 +'1516388144210500300' == 1516388144210500400 +'1516388144210500400' == 1516388144210500400 

You can see that, when converting those strings to numbers, they get rounded to the nearest available IEEE-754 double-precision (64 bit) number. This is because 1516388144210500000 > Number.MAX_SAFE_INTEGER.

Is there truncation of some kind of going on, which trims the string and makes it more likely to get duplicates?

Yes, simply by rounding a random number, you cut off the fractional digits. This reduces the number of possible outcomes compared to the non-rounded random number.

In addition to that, you concatenate a timestamp (13 digits) with a value between 0 and 1000000 (1 to 7 digits). So your concatenated result will have a total number of 14 to 20 digits, but JavaScript's number datatype is of limited precision and represents integers faithfully up to about 16 digits only (see Number.MAX_SAFE_INTEGER).

Example: Let's assume the timestamp is 1516388144210 and you append random numbers from 500000 to 500400:

+'1516388144210500000' == 1516388144210500000 +'1516388144210500100' == 1516388144210500000 +'1516388144210500200' == 1516388144210500000 +'1516388144210500300' == 1516388144210500400 +'1516388144210500400' == 1516388144210500400 

You can see that, when converting those strings to numbers, they get rounded to the nearest available IEEE-754 double-precision (64 bit) number. This is because 1516388144210500000 > Number.MAX_SAFE_INTEGER.

Source Link
le_m
  • 20.4k
  • 10
  • 70
  • 78

Is there truncation of some kind of going on, which trims the string and makes it more likely to get duplicates?

Yes, you concatenate a timestamp (13 digits) with a value between 0 and 1000000 (1 to 7 digits). So your concatenated result will have a total number of 14 to 20 digits, but JavaScript's number datatype is of limited precision and represents integers faithfully up to about 16 digits (Number.MAX_SAFE_INTEGER).

Example: Let's assume the timestamp is 1516388144210 and you append random numbers from 500000 to 500400:

+'1516388144210500000' == 1516388144210500000 +'1516388144210500100' == 1516388144210500000 +'1516388144210500200' == 1516388144210500000 +'1516388144210500300' == 1516388144210500400 +'1516388144210500400' == 1516388144210500400 

You can see that, when converting those strings to numbers, they get rounded to the nearest available IEEE-754 double-precision (64 bit) number. This is because 1516388144210500000 > Number.MAX_SAFE_INTEGER.