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関数でランダムに取得します
シャッフル回数は45回
3,シャッフル後の配列の要素を表示しています
Array
(
[0] => 31
[1] => 19
[2] => 24
[3] => 36
[4] => 27
[5] => 33
[6] => 41
[7] => 17
[8] => 37
[9] => 11
[10] => 16
[11] => 4
[12] => 12
[13] => 42
[14] => 35
[15] => 8
[16] => 10
[17] => 23
[18] => 7
[19] => 5
[20] => 34
[21] => 15
[22] => 14
[23] => 29
[24] => 26
[25] => 30
[26] => 25
[27] => 2
[28] => 6
[29] => 20
[30] => 1
[31] => 43
[32] => 13
[33] => 3
[34] => 9
[35] => 39
[36] => 40
[37] => 32
[38] => 21
[39] => 28
[40] => 18
[41] => 22
[42] => 38
)
4,シャッフルした配列の要素の前から6個を取り出し、表示しています
Array
(
[0] => 31
[1] => 19
[2] => 24
[3] => 36
[4] => 27
[5] => 33
)
5,取り出した要素を順番に並び替えて表示しています
これがランダムに生成されたloto6の番号となります
Array
(
[0] => 19
[1] => 24
[2] => 27
[3] => 31
[4] => 33
[5] => 36
)