Fixed values of randn at starting?

5 Ansichten (letzte 30 Tage)
Hema Aggarwal
Hema Aggarwal am 3 Mär. 2017
Beantwortet: Guillaume am 3 Mär. 2017
I am using 'randn' function but on every run values is keep changing,how can i fixed that?
  1 Kommentar
KSSV
KSSV am 3 Mär. 2017
The purpose of randn is to generate Normally distributed random numbers. It keeps changing for every call. Read the documentation.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 3 Mär. 2017
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

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by