Generating random number between 1 to 10 but having discrete steps

조회 수: 4 (최근 30일)
Arsal15
Arsal15 2016년 2월 3일
편집: Joseph Cheng 2016년 2월 3일
Hi,
I want to generate random time steps to test my function. As i have to give random time and it will generate output on that time value. any simple solution.
As i have tried before this method.
if true
N =10;
randperm(N);
%giving me
output = 5 2 10 3 8 1 9 7 4 6
%But i want output as
output = 1.857 3.597 2.684 7.158 9.516 5.535
end
Need your guidance.

채택된 답변

Guillaume
Guillaume 2016년 2월 3일
output = rand(1, 10) * 10;
There's no guarantee that the 10 values are unique but the probability that you have two identical values is extremely small.
  댓글 수: 1
Joseph Cheng
Joseph Cheng 2016년 2월 3일
편집: Joseph Cheng 2016년 2월 3일
to expand on that why not use what you have but add the decimal as rand as well.
N =10;
output = randperm(N)+rand(1,10)
or instead of randperm you can use randi(10,1,numtests)+rand(1,numtests) where numtests is the number of test cases you're putting in.

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

추가 답변 (0개)

카테고리

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