阅读:JAVA 3& 4

博客围绕Java展开,介绍了随机数生成,提到可通过构造函数设置种子以重复生成相同随机数,还讲解了类型确定用instanceof,介绍了Long、Double、Float类型常量的表示,以及for - 循环的使用示例。
  • 随机数:
Random rand = new Random(47); // 产生随机算子。47 is seed. for incovating predicatable random number
int i = rand.nextInt(100); // 100 is range of random number

Random()

“Creates a new random number generator. This constructor sets the seed of the random number generator to a value very likely to be distinct from any other invocation of this constructor. “

The seed is probably a derivative of the current time, or the current time itself. That should be enough to be “very likely to be distinct from any other invocation”. Which, in essence, is most likely what you need, most of the time.

So why have another constructor that takes a seed?

Simply put, if you want to generate the same set of random numbers over and over, you use the same seed on your Random constructor. This is useful when doing experiments on different control sets, and you don’t want to bother creating your own table of random inputs, but still want the same set of random input on a different experiment/control set.

  • 类型确定

instanceof. String i = ''; i instanceof String. However, i instanceof int will have compiler error.

  • 常量

Long 3000L/l

Double 2.33D/d

Float 3.44f/F

int i1 = 0x23;
String ii = Integer.toBinaryString(i1);
  • for-循环

for(char s: 'hello world'.toCharArray()){

}

转载于:https://www.cnblogs.com/connie313/p/10549563.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值