Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
乱数を生成するためにさまざまな方法を試しましたが、負の範囲と正の範囲で機能する単純なnextInt(int min、int max)メソッドを作成できないようです。
10〜20 -10〜10 -10〜-20
一方の範囲で機能させると、もう一方の範囲は機能しません。
何を試しましたか?
rnd.nextInt(max+1-min)+min;
限り機能するはずmin < maxです。max排他が必要な場合は、を削除し+1ます。
min < max
+1