필터 지우기
필터 지우기

random number generating problems

조회 수: 1 (최근 30일)
alexaa1989
alexaa1989 2014년 8월 19일
댓글: alexaa1989 2014년 8월 21일
hi everyone I have written an algorithm in which there is a part that has to produce random numbers like this:
a=randi(10,1,4)
b=randi(10,1,4)
c=randi(10,1,4)
I need it to produce different sets of numbers everytime I run the algorithm but it uses the same sets of numbers everytime
can anyone help?

답변 (1개)

Guillaume
Guillaume 2014년 8월 19일
In all likelyhood, you're seeding the random number generator with a fixed seed somewhere before calling randi.
Look for a rng(...) instruction and remove it, or insert a rng('shuffle') before calling randi. rng('shuffle') seeds the generator with the current time.
  댓글 수: 2
Iain
Iain 2014년 8월 19일
편집: Iain 2014년 8월 19일
If you aren't setting the random number generator with ANY seed, try ensuring that you provide one based on say, the time of day.
alexaa1989
alexaa1989 2014년 8월 21일
it isn't working with rng and now it is producing not feasible solutions

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by