どうも、ちょげ(@chogetarou)です。
int型の整数の乱数を生成する方法を紹介します。
方法

int型の整数の乱数を取得するには、RandomクラスのNext()を使います。
まず、Randomクラスのインスタンスを用意します。
Random rnd = new Random();
そして、用意したRandomクラスのインスタンスからNext()を呼び出します。
rnd.Next()
Next()は、int型の整数の乱数を返します。
使用例
using System;
public class Example
{
public static void Main()
{
Random rnd = new Random();
for (var i = 0; i < 5; i++)
{
Console.WriteLine(rnd.Next());
}
}
}
/*
出力:
457427235
1627990271
1590565133
788593872
1035176398
*/
コメント