P
P
pojlzghb2018-02-19 13:22:42
PHP
pojlzghb, 2018-02-19 13:22:42

PHP random big numbers?

Hello. I need to generate a random number from 0 to ~2^63-1
How can this be done? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2018-02-19
@xmoonlight

How can this be implemented?

1. You need to create a storage system for long integers or real numbers (fixed or floating point). Namely, programming.
2. Then, using the recreated random() function for the new numbers, generate random numbers.
3. Profit!

S
Stalker_RED, 2018-02-19
@Stalker_RED

Find out what is the maximum number that can be obtained using getrandmax() , and if the limit does not suit you, then generate several numbers and concatenate them (like strings, I guess).
Something like:

$number = '';
$max = getrandmax();
while (strlen($number) < $n) {
  $number .= rand($max);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question