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