java random和math。random
时间: 2023-08-28 08:16:36 浏览: 89
Java 随机数总结 三种不同随机数方法
Java中的随机数生成有两种方式:Random和Math.random()。
使用Random类可以生成指定范围内的随机整数。可以使用nextInt()方法来生成之间的随机整数,可以使用(int)(Math.random() * 100) + 1。Math.random()方法在多线程环境下是线程安全的,可以被同时调用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Java中Random类和Math.Random()用法](https://blog.csdn.net/weixin_42310154/article/details/120826322)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [JAVA 随机数,Math.random() Random类](https://blog.csdn.net/YDHIT/article/details/131307774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文