java.util.Random 类

//: object/ForEachFloat.java
package object; import java.util.Random;
public class ForEachFloat
{
public static void main(String[] args)
{
Random rand = new Random();//47是随机种子,如果不提供种子,默认为系统时间
float f[] = new float[10];
for(int i = 0; i < 10; i++)
f[i] = rand.nextFloat(); //生成0-1之间的float值
/*nextInt(100)+1 //100 + i是生成的int值的上限(不包括100+i),1为我们设定的下限(包括1),下限默认为0
* nextLong()
* nextDouble()
*/
for(int i = 0; i < 10; i++)
System.out.printf("%f\t",f[i]);
System.out.println('\n');
for(float x : f) //将f数组的值按顺序赋予x
System.out.printf("%f\t",x);
}
}
上一篇:RocketMq发送消息出现com.alibaba.rocketmq.client.exception.MQBrokerException: CODE: 2 DESC: [TIMEOUT_CLEAN_QUEUE]broker busy, start flow control for a while, period in queue: 201ms, size of queue: 1


下一篇:爬虫初窥day1:urllib