双随机数和数组 [英] double random number and array

查看:96
本文介绍了双随机数和数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是整数中的随机代码gen,对吧?

this is the code random gen in integer, right?

Random random = new Random();
int irandom = random.Next(1, 100);


随机生成的双倍数又如何呢?
从0.0到100.0


what about for random gen in double?
from 0.0 to 100.0

and how make an array (25 to 50) random numbers?

推荐答案

您可以使用NextDoubleSample并将其添加到随机整数中.
参考: http://msdn.microsoft.com/en-us/library/system. random.nextdouble.aspx [ ^ ]

您可以生成n个随机数,并将其放入数组或任何其他形式.尝试一下.
You can use NextDouble or Sample and add it to your random integer.
Ref: http://msdn.microsoft.com/en-us/library/system.random.nextdouble.aspx[^]

You can generate n number of randoms and put it in array or whatever. Try it.


引用该线程
http://stackoverflow.com/questions/609501/generating-a-random-小数的c锐度 [ ^ ]
Refer this thread
http://stackoverflow.com/questions/609501/generating-a-random-decimal-in-c-sharp[^]


获取0到1000之间的随机数,然后将其映射到0到100以获取1到100之间的随机数(带小数点)点精度.

get a random number between 0 and 1000 and then map it to 0 to 100 to get a random number between 1 and 100 with one decimal point precision.

public static double getrand()
{
    Random random = new Random();

    return random.Next(0, 1000)/10.0;
}


这篇关于双随机数和数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆