如何产生随机数
来源:互联网 发布:大学生兼职知乎 编辑:程序博客网 时间:2024/06/05 15:31
常用 Math.random() 来获得一个0.1到1.0之间的double 值,不包括1.0
比如随机产生十个减法算式:
public static void main(String[] args) {
for(int i = 0;i<10;i++){
int number1 = (int)(Math.random()*10);
int number2 = (int)(Math.random()*10);
if(number1 < number2){
int t = number1;
number1 = number2;
number2 = t;
}
System.out.println("What is the "+number1+"-"+number2 );
Scanner input = new Scanner(System.in);
int answer = input.nextInt();
if(number1 - number2 ==answer){
System.out.println("True");
}
else{
System.out.println("False");
}
结果为:
What is the 9-8
2
False
What is the 4-1
3
True
0 0
- [C]如何产生随机数~
- 如何产生一个随机数
- J2ME如何产生随机数
- 如何产生随机数
- 如何产生随机数
- 编程-如何产生随机数
- 如何产生随机数
- 如何产生各种随机数
- 如何产生真正随机数
- 如何产生各种随机数
- 如何产生随机数
- 如何产生随机数
- 如何产生随机数
- 如何产生不相等的随机数
- vc++中如何产生随机数
- ORACLE 如何产生一个随机数
- Java中如何产生随机数
- Java中如何产生随机数
- mina —— 分布式集群下长连接session共享的解决方案
- Python程序转换为exe程序,py2exe的使用方法
- Leetcode-121. Best Time to Buy and Sell Stock
- 2c问题记录
- 增加计时函数 GPGPU编程技术-从GLSL、CUDA到OpenCL 平方和算法第一版
- 如何产生随机数
- 欧拉工程第29题 a的b次方(2≤a,b≤100)中共有多少个不同的数
- linux下安装svn及配置
- powercfg
- 基于TestNG使用PowerMock的Mockito扩展在Maven测试项目中的配置说明
- 集合框架笔记6(备忘)
- 读书笔记:Deep Learning [Ada-Computation&ML series]--chapter13.Linear factor model
- JavaScript中函数参数的值传递和引用传递
- Selenium IDE录制测试弹出窗口