計算機科学のブログ

namespaces and classes - Organizing your code - Random class, double, array

Head First C Sharp: A Learner’s Guide to Real-World Programming with C Sharp and .NET (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)の Chapter 3(namespaces and classes - Organizing your code)、p.163(Sharpen your pencil)の解答を求めてみる。

コード

Program.cs

double[] randomDoubles = new double[20];

for (int i = 0; i < randomDoubles.Length; i++)
{
    double vaule = Random.Shared.NextDouble();
    randomDoubles[i] = vaule;
}

foreach (double item in randomDoubles)
{
    Console.WriteLine(item);
}

入出力結果(Terminal, Zsh)

0.8203004724220033
0.2013234087247261
0.8259047027069978
0.692723577962753
0.17742910388360278
0.42237824014494707
0.8995387270780058
0.2891128004558705
0.9214084274953328
0.7448014797814241
0.9091834153038237
0.4923717509282002
0.3854232790839869
0.9149517590151482
0.46264698295854256
0.8408752505261888
0.8490951502445844
0.15325290568728533
0.5496328332372529
0.688009432410309