
java中 下列哪些是调用Math.random()可能输出的? 323.4,0.5,34,1.0,0.0,0.234 告诉我原理
3个回答
展开全部
所以可能结果是: 0.5, 0.0, 0.234
Math.random()
public static double random()返回带正号的 double 值,大于或等于 0.0,小于 1.0。返回值是一个伪随机 (pseudorandomly) 选择的数,在上述范围内(大致)均匀分布。
第一次调用该方法时,它将创建一个新的伪随机数生成器,其表达与以下表达非常类似
new java.util.Random之后,新的伪随机数生成器可用于该方法的所有调用,但不能用于其他地方。
在经过适当同步后,允许多个线程正确地使用该方法。然而,如果很多线程需要以极高的速率生成伪随机数,那么这可能会减少每个线程对拥有自己的伪随机数生成器的争用。
返回:
大于或等于 0.0 但小于 1.0 的伪随机 double 值。
Math.random()
public static double random()返回带正号的 double 值,大于或等于 0.0,小于 1.0。返回值是一个伪随机 (pseudorandomly) 选择的数,在上述范围内(大致)均匀分布。
第一次调用该方法时,它将创建一个新的伪随机数生成器,其表达与以下表达非常类似
new java.util.Random之后,新的伪随机数生成器可用于该方法的所有调用,但不能用于其他地方。
在经过适当同步后,允许多个线程正确地使用该方法。然而,如果很多线程需要以极高的速率生成伪随机数,那么这可能会减少每个线程对拥有自己的伪随机数生成器的争用。
返回:
大于或等于 0.0 但小于 1.0 的伪随机 double 值。
展开全部
请看API,只能产生0(含)到1(不含)之间的double型的随机数
random
public static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression
new java.util.Random
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.
This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
Returns:
a pseudorandom double greater than or equal to 0.0 and less than 1.0.
See Also:
Random.nextDouble()
random
public static double random()
Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression
new java.util.Random
This new pseudorandom-number generator is used thereafter for all calls to this method and is used nowhere else.
This method is properly synchronized to allow correct use by more than one thread. However, if many threads need to generate pseudorandom numbers at a great rate, it may reduce contention for each thread to have its own pseudorandom-number generator.
Returns:
a pseudorandom double greater than or equal to 0.0 and less than 1.0.
See Also:
Random.nextDouble()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
0 到 1 之间的数 0.5, 0.0, 0.234
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询