Fixed values of randn at starting?

조회 수: 4 (최근 30일)
Hema Aggarwal
Hema Aggarwal 2017년 3월 3일
답변: Guillaume 2017년 3월 3일
I am using 'randn' function but on every run values is keep changing,how can i fixed that?
  댓글 수: 1
KSSV
KSSV 2017년 3월 3일
The purpose of randn is to generate Normally distributed random numbers. It keeps changing for every call. Read the documentation.

댓글을 달려면 로그인하십시오.

답변 (1개)

Guillaume
Guillaume 2017년 3월 3일
If you want to have the same stream of random numbers every time you run your code, simply set the seed of the random generator to a constant value of your choice, using rng
>>rng(1234); %choose whatever number you want
>>randn(1, 2)
ans =
-0.947246643957371 0.540149747070348
>>randn(1, 2)
ans =
-0.216602140976276 1.18903197494834
>>%...later
>>rng(1234); %same seed as before, produces the same sequence
>>randn(1, 2)
ans =
-0.947246643957371 0.540149747070348
>>randn(1, 2)
ans =
-0.216602140976276 1.18903197494834

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by