由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - java random set seed question
相关主题
请教几个C++问题what is the difference?
Synthesized Constructor到底什么意思?问个构造函数的问题
[合集] 又学了一招菜鸟请教smart pointer
请教个Bloomberg 的 C++ 题目help understanding code (random number)
Is the order of initialization a, b, c or c, b, a?Randomization of an array
一个c++ constructor的问题, thanksRandom Switch Between Two Different URLs
question about Design Patterns关于数组动态分配的疑问???
c++ questionC++ 中 myobject * a =new myobject[n] 的问题
相关话题的讨论汇总
话题: random话题: setid话题: seed话题: set话题: java
进入Programming版参与讨论
1 (共1页)
J*y
发帖数: 271
1
java 有经验的,帮忙看看这个问题:
if (Math.random()>.5)
setid=2;
else
setid=1;
怎样set seed, 使setid 值固定,便于检验结果?
3x
g*****g
发帖数: 34805
2
Math.random()的值永远<1,所以setid=2.
Math.random调用的是Random的缺省constructor, 缺省constructor调用的是
Random() { this(System.currentTimeMillis()); }
所以如果你要固定的序列,用
public Random(long seed)方法
比如类似
Random random = new Random(0);
setid = random.nextInt(10) > 5? 2:1;

【在 J*y 的大作中提到】
: java 有经验的,帮忙看看这个问题:
: if (Math.random()>.5)
: setid=2;
: else
: setid=1;
: 怎样set seed, 使setid 值固定,便于检验结果?
: 3x

J*y
发帖数: 271
3
thanks
yes. have to use random. math.random cannot set seed.

【在 g*****g 的大作中提到】
: Math.random()的值永远<1,所以setid=2.
: Math.random调用的是Random的缺省constructor, 缺省constructor调用的是
: Random() { this(System.currentTimeMillis()); }
: 所以如果你要固定的序列,用
: public Random(long seed)方法
: 比如类似
: Random random = new Random(0);
: setid = random.nextInt(10) > 5? 2:1;

1 (共1页)
进入Programming版参与讨论
相关主题
C++ 中 myobject * a =new myobject[n] 的问题Is the order of initialization a, b, c or c, b, a?
c++:constructor 一问一个c++ constructor的问题, thanks
Test your C++ knowledge...question about Design Patterns
How to initialize object in constructor?c++ question
请教几个C++问题what is the difference?
Synthesized Constructor到底什么意思?问个构造函数的问题
[合集] 又学了一招菜鸟请教smart pointer
请教个Bloomberg 的 C++ 题目help understanding code (random number)
相关话题的讨论汇总
话题: random话题: setid话题: seed话题: set话题: java