loto6・7番号生成 基本デモ02


「loto6・7番号生成 基本デモ01」をloto6に当てはめてみます
1から43までの数字を配列に入れてシャッフルします。
シャッフル回数をrand()関数でランダムに取得し、その回数分シャッフルしています
シャッフルした配列の要素を前から6個取り出します。
取り出した要素を順番に並び替えます。

⇒ 記事内容はこちら

1,loto6用に1から43までの数字を要素とする配列を準備します
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
    [10] => 11
    [11] => 12
    [12] => 13
    [13] => 14
    [14] => 15
    [15] => 16
    [16] => 17
    [17] => 18
    [18] => 19
    [19] => 20
    [20] => 21
    [21] => 22
    [22] => 23
    [23] => 24
    [24] => 25
    [25] => 26
    [26] => 27
    [27] => 28
    [28] => 29
    [29] => 30
    [30] => 31
    [31] => 32
    [32] => 33
    [33] => 34
    [34] => 35
    [35] => 36
    [36] => 37
    [37] => 38
    [38] => 39
    [39] => 40
    [40] => 41
    [41] => 42
    [42] => 43
)

2,シャッフル回数をrand関数でランダムに取得します
シャッフル回数は34回


3,シャッフル後の配列の要素を表示しています
Array
(
    [0] => 39
    [1] => 16
    [2] => 41
    [3] => 32
    [4] => 18
    [5] => 34
    [6] => 6
    [7] => 26
    [8] => 28
    [9] => 24
    [10] => 40
    [11] => 12
    [12] => 2
    [13] => 8
    [14] => 14
    [15] => 15
    [16] => 36
    [17] => 31
    [18] => 1
    [19] => 42
    [20] => 3
    [21] => 27
    [22] => 33
    [23] => 29
    [24] => 22
    [25] => 21
    [26] => 30
    [27] => 13
    [28] => 20
    [29] => 7
    [30] => 9
    [31] => 43
    [32] => 10
    [33] => 35
    [34] => 19
    [35] => 25
    [36] => 23
    [37] => 37
    [38] => 11
    [39] => 4
    [40] => 5
    [41] => 17
    [42] => 38
)

4,シャッフルした配列の要素の前から6個を取り出し、表示しています
Array
(
    [0] => 39
    [1] => 16
    [2] => 41
    [3] => 32
    [4] => 18
    [5] => 34
)

5,取り出した要素を順番に並び替えて表示しています
これがランダムに生成されたloto6の番号となります
Array
(
    [0] => 16
    [1] => 18
    [2] => 32
    [3] => 34
    [4] => 39
    [5] => 41
)