Randi(imax,m,n)

조회 수: 6 (최근 30일)
Moazam Ali
Moazam Ali 2020년 6월 17일
편집: James Tursa 2020년 6월 18일
How to increase the size of the argument imax in randi function. I used the code e=randi(phi,1,1) but there comes an error saying value of phi has to be less than 2^52. What to do to increase this range?
  댓글 수: 2
Matt J
Matt J 2020년 6월 17일
Increase it by how much?
Moazam Ali
Moazam Ali 2020년 6월 18일
The phi I used here is of the order of 2^1024

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

답변 (2개)

James Tursa
James Tursa 2020년 6월 17일
편집: James Tursa 2020년 6월 17일
The point is that once the eps of the max value is greater than 1, you cannot represent contiguous sets of integer values in double precision. E.g.,
>> eps(2^52)
ans =
1
>> eps(2^53)
ans =
2
So double precision could represent 2^52 + 1 exactly, but you see it will not be able to represent 2^53 + 1 exactly because eps(2^53) is greater than 1. So then the question becomes what makes sense for randi to produce as output when it can't represent all of the integers in the desired range? It doesn't make sense, hence the restriction.
  댓글 수: 1
Matt J
Matt J 2020년 6월 17일
And that is why my answer involves a conversion to uint64.

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


Matt J
Matt J 2020년 6월 17일
Perhaps as follows,
num = uint64(randi(2^53-1,1))*2^8 +randi(2^8-1,1)
  댓글 수: 2
Moazam Ali
Moazam Ali 2020년 6월 18일
Uint 64 represents the variables as 64bit data but anything beyond that limit is stored as 2^64-1. Isn't it going to effect the random selection
James Tursa
James Tursa 2020년 6월 18일
편집: James Tursa 2020년 6월 18일
Using uint64 extends the allowed range beyond double, but of course it has a limit as well as you note. If you really need more range then use more than one variable for each value you need and extend Matt's approach.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by