Reply to thread

This might be better.

[CODE=php]

function randomChance($min, $max) {

    return random_int($min, $max);

}

[/CODE]

The random_int function generates cryptographically secure pseudo-random integers.

So you can guarantee randomness. The mt_rand function can be predictable.

Also you could also rewrite your randomLotteryNumber function like this.

[CODE=php]

function randomLotteryNumber() {

    return strval(random_int(1000, 9999));

}

[/CODE]

You will get the same results as the old function but this version is faster because

the random integer function is called once. Also you could add type-hints if your php

version is up to date. For example:

[CODE=php]

function randomLotteryNumber(): string {

    return strval(random_int(1000, 9999));

}

[/CODE]


Top