'Generate random x numbers between the range of z and y in PHP [closed]

Is there a way to generate 65 random number in an array between the numbers 24 - 51 in php. Thats just an example of what I'm trying to do. I keep finding just range of two number or picking one number but not generating 65 numbers, that will repeat, between a range of numbers.



Solution 1:[1]

to generate 65 random number in an array between the numbers 24 - 51 you may use for loop and mt_rand function.

$arr = [];
$n = 65;
$r_min = 24;
$r_max = 51;
for ($i = 1; $i <= $n; $i++) {
    $arr[] = mt_rand($r_min, $r_max);
}
print_r($arr);

will print for example: (output will change every time of course)

Array
(
    [0] => 50
    [1] => 37
    [2] => 44
    [3] => 48
    [4] => 31
    [5] => 30
    [6] => 29
    [7] => 51
    [8] => 34
    [9] => 32
    [10] => 41
    [11] => 25
    [12] => 41
    [13] => 26
    [14] => 51
    [15] => 42
    [16] => 31
    [17] => 44
    [18] => 51
    [19] => 41
    [20] => 25
    [21] => 46
    [22] => 26
    [23] => 45
    [24] => 26
    [25] => 26
    [26] => 26
    [27] => 33
    [28] => 32
    [29] => 48
    [30] => 29
    [31] => 39
    [32] => 46
    [33] => 40
    [34] => 25
    [35] => 49
    [36] => 51
    [37] => 45
    [38] => 49
    [39] => 45
    [40] => 38
    [41] => 30
    [42] => 46
    [43] => 48
    [44] => 49
    [45] => 24
    [46] => 50
    [47] => 26
    [48] => 50
    [49] => 35
    [50] => 46
    [51] => 25
    [52] => 49
    [53] => 42
    [54] => 45
    [55] => 42
    [56] => 39
    [57] => 37
    [58] => 42
    [59] => 43
    [60] => 46
    [61] => 33
    [62] => 51
    [63] => 50
    [64] => 24
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ersin