Random
Usage
• Random[ ] 用来给出0和1之间均匀分布的伪随机数.
• Random[type, range] 给出指定范围内指定类型的伪随机数. 可能的类型有:Integer, Real和Complex. 缺省的范围是
0到1.你可以明确指定范围 min, max ; max的范围指定等价于 0, max .
Notes
• Random[Integer] 以等概率  给出0或1. • Random[Complex] 给出以0和  为顶角的矩形中的一个复伪随机数. • Random[Complex, zmin, zmax ] 给出以 zmin 和 zmax为顶角的矩形中的伪随机数. • Random[Real, range, n]给出一个n-位精度的随机数. 主数位和尾数位都可以选为0. • 不管你什么时候运行Mathematica,Random都返回一个不同的伪随机数序列. 你可以通过使用SeedRandom用特定种子启动Random.
Further Examples
This generates a random integer in the range from 1 to 100.
In[1]:=
|
Out[1]=
|
Here is a random real number in the range from 0 to 10.
In[2]:=
|
Out[2]=
|
Here is a random real number in the range from 0 to 1.
In[3]:=
|
Out[3]=
|
If you want to use a different distribution to generate random numbers, then you have to first load the package ContinuousDistributions.m.
In[4]:=
|
Then, to generate random numbers with a log normal distribution, for example,
In[5]:=
|

In[6]:=
|
In[7]:=
|
Out[7]=
|
If you need repeatable results, you can reseed the random number generator.
In[8]:=
|
In[9]:=
|
Out[9]=
|
In[10]:=
|
In[11]:=
|
Out[11]=
|
|