我是C#的初學者我已經創建了這個程序來產生7個隨機數,並在控制檯中顯示它們。但現在我想要在18.0-23.5範圍內生成小數。 但我無法弄清楚如何?我用Next.Double
嘗試過,但我無法使它工作。請幫助!帶小數點的隨機數
這裏是我的程序:
int lotto1 = 0, lotto2 = 0, lotto3 = 0, lotto4 = 0, lotto5 = 0, lotto6 = 0, lotto7 = 0;
Random rnd = new Random();
Console.WriteLine("Din lottorad är:");
lotto1 = rnd.Next(1, 36);
Console.WriteLine("Nr1: " + lotto1);
lotto2 = rnd.Next(1, 36);
Console.WriteLine("Nr2: " + lotto2);
lotto3 = rnd.Next(1, 36);
Console.WriteLine("Nr3: " + lotto3);
lotto4 = rnd.Next(1, 36);
Console.WriteLine("Nr4: " + lotto4);
lotto5 = rnd.Next(1, 36);
Console.WriteLine("Nr5: " + lotto5);
lotto6 = rnd.Next(1, 36);
Console.WriteLine("Nr6: " + lotto6);
lotto7 = rnd.Next(1, 36);
Console.WriteLine("Nr7: " + lotto7);
http://stackoverflow.com/questions/609501/generating- a-random-decimal-in-c-sharp – Habib
你只想要一個小數位嗎?在180到235之間生成整數值,然後除以十。 –
在發佈問題之前至少搜索一次! –