I would like to generate random numbers between 1 & 10, with a decimal place of 1
(e.g. 1.5, 9.4, 6.3, 2.9)
I would like to generate random numbers between 1 & 10, with 2 decimal places
(e.g. 1.51, 9.46, 6.32, 2.93)
I would like to generate random numbers between 1 & 10, with 3 decimal places
(e.g. 1.512, 9.346, 6.329, 2.935)
一種解決方案是將一個隨機數生成器僅用於小數位,然後與數字連接。有沒有更簡單的方法來實現這一點?如何生成一個具有小數位的隨機數
嘗試java.util.Random – Sid 2010-11-10 10:46:05