日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java2组随机数的共通数_java随机数产生-指数分布 正态分布 等

發布時間:2024/7/23 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java2组随机数的共通数_java随机数产生-指数分布 正态分布 等 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1 指數分布

指數分布的概率密度函數:y=lamda*exp(-lamda*x)

x>=0

由此可以計算概率分布函數:y=1-exp(-lamda*x)

x>=0

y是 ?X

首先,把y當作是在(0,1)區間的均勻分布的隨機變量。

然后,求y=1-exp(-lamda*x)的逆函數,x=-(1/lamda)*ln(1-y)

令z=1-y,顯然z也是(0,1)區間的均勻分布的隨機變量,于是就有x=-(1/lamda)*ln(z)。

z可以通過(double)

rand() ?/ ?RAND_MAX計算。原因是rand() ?是隨機分布函數。

最終滿足指數分布的變量x,就可以通過x=-(1/lamda)*ln(z)計算。

import

java.util.*;

public class zhishu

{

public

static void main(String[] args) {

double x,

z;

double

lamda;

System.out.println("請輸入lamda的值:");

Scanner

scanner = new Scanner(System.in);

lamda =

scanner.nextDouble();

for(int i=0;

i<10; i++) {

z =

Math.random();

x = -(1 /

lamda) * Math.log(z);

System.out.println(x);

}

}

}

----------------------------------------------------------------------

2

正態分布

java.util.Random里的nextGaussian(),生成的數值符合均值為0方差為1的高斯/正態分布,即符合標準正態分布。

產生數字的范圍:任何數都有可能,不過在0左右的數字較多。

產生N(a,b)的數:Math.sqrt(b)*random.nextGaussian()+a; 即均值為a,方差為b的隨機數

--------------------------------------------------------------------------------------

3 擴展:使用[0,1]之間的均勻分布生成任意一個分布函數的隨機數序列

任務:給定一個分布的密度函數f(x),要生成滿足這一分布的一組隨機數。

輸入:一組[0,1]之間的滿足均勻分布的隨機數U

輸出:一組滿足f(x)的隨機數V

方法:1)求f(x)的分布函數F(x)

2)求F(x)的反函數F'(x)

3)對于U中的每一個元素u,將F'(u)加入序列V中。

4 其他:colt庫中有隨機數發生器

cern.jet.random.Distributions

Method Summary

static?double

k,

double?p)?Returns

the probability distribution function of the discrete geometric

distribution.

static?double

r,

int?nr,?RandomEngine?randomGenerator)?Returns

a random number from the Burr II, VII, VIII, X Distributions.

static?double

r,

double?k,

int?nr,?RandomEngine?randomGenerator)?Returns

a random number from the Burr III, IV, V, VI, IX, XII

distributions.

static?double

Returns

a cauchy distributed random number from the standard Cauchy

distribution C(0,1).

static?double

variance,

double?mean,?RandomEngine?randomGenerator)?Returns

an erlang distributed random number with the given variance and

mean.

static?int

p,?RandomEngine?randomGenerator)?Returns

a discrete geometric distributed random

number;

static?double

l3,

double?l4,?RandomEngine?randomGenerator)?Returns

a lambda distributed random number with parameters l3 and l4.

static?double

Returns

a Laplace (Double Exponential) distributed random number from the

standard Laplace distribution L(0,1).

static?double

Returns

a random number from the standard Logistic distribution

Log(0,1).

static?double

alpha,

double?cut,?RandomEngine?randomGenerator)?Returns

a power-law distributed random number with the given exponent and

lower cutoff.

static?double

Returns

a random number from the standard Triangular distribution in

(-1,1).

static?double

alpha,

double?beta,?RandomEngine?randomGenerator)?Returns

a weibull distributed random number.

static?int

z,?RandomEngine?randomGenerator)?Returns

a zipfian distributed random number with the given skew.

總結

以上是生活随笔為你收集整理的java2组随机数的共通数_java随机数产生-指数分布 正态分布 等的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。