Random.NextDoubleに相当する、実数型の乱数を生成するメソッドは用意されていません。 GetInt32メソッドが使用できない場合や、実数型の乱数を生成したい場合は、RandomNumberGeneratorから生成したバイト列を型変換して目的の型・値域の乱数に変換する、などの方法をとる必要があります。
RandomNumberGeneratorで生成した乱数列を整数の乱数に変換する
Imports System
Imports System.Security.Cryptography
Class Sample
Shared Sub Main()
Using rng As RandomNumberGenerator = RandomNumberGenerator.Create()
' 1〜6までの整数乱数を20個生成して表示する
Dim uint32rand(3) As Byte
For i As Integer = 1 To 20
rng.GetBytes(uint32rand)
' 乱数バイト列を1から6までの整数に変換
'/ (バイト列乱数をUInt32型に変換してから、double[0.0, 1.0)→int[1, 6]に変換する)
Dim val As Integer = 1 + CInt(Math.Truncate(6.0 * BitConverter.ToUInt32(uint32rand, 0) / (UInteger.MaxValue + 1.0)))
Console.Write($"{val}, ")
Next
Console.WriteLine()
End Using
End Sub
End Class
実行結果の一例
3, 4, 1, 5, 1, 1, 5, 3, 4, 3, 2, 1, 1, 5, 5, 1, 2, 6, 2, 3,