Actually, I call $CardCookie = mt_rand(6103006430040008016, 6103006430040020000); , at the output when generating some cards it gets out of the specified range, it is noticed that there are 24 values ​​somewhere.

How to treat?

  • I have great suspicions that even for a 64bit system you have exceeded the maximum value for an integer here. - Visman
  • How to be? I need to generate maps in these ranges - K.Mitnick
  • Диапазон min - max не должен выходить за границы mt_getrandmax(). То есть (max - min) <= mt_getrandmax(). В противном случае, mt_rand() может возвращать менее качественные случайные числа. - Alexey Shimansky
  • four
    Select the prefix from the number 1030064300 and generate only the remaining part from 40008016 to 40020000. In response, return the string, not the number obtained by concatenating string 1030064300 and the result of the generation. - Visman
  • @ AlekseyShimansky, well, the difference between max and min is just small there - Kirill Malyshev

2 answers 2

mt_getrandmax (); - will show whether the threshold of the maximum possible random number of the returned mt_rand is not exceeded. If so, mt_rand may give an error.

 mt_rand(min, max); (max - min) <= mt_getrandmax() 
  • Implemented through this solution: $ randCanc = 61030064300; $ randGen = mt_rand (40008016,40020000); $ CardCookie = $ randCanc. $ randGen; - K.Mitnick

The number is too large and cannot be represented exactly in the double type.

You may notice that C ++ displays another value: https://ideone.com/2pJ4uh

 printf("%.0f", 6103006430040020000.); 
 6103006430040019968 

Related question: Displaying the number 9223372036854775807