Research randi, fix, round, ceil, floor functions. • Can you generate a random integer number without using randi?

조회 수: 8 (최근 30일)
Help me please
  댓글 수: 1
Medu Segar
Medu Segar 2020년 10월 24일
Research randi, fix, round, ceil, floor functions.
Can you generate a random integer number without using randi?
If the answer is yes, how?
If the answer is no, why not?
In this

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 10월 24일

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 10월 24일
Yes, you can. You can use rand() and typecast the results to uint64 and that will be an integer.
The question only asks about creating an integer, and does not impose any restrictions about range of the integers or that the integers produced must be sampled consecutively or that the sampling must follow any particular distribution or that the sampling must be unbiased.
Caution: I know what the expected answer is to the question, but the techniques that they are hinting at are not unbiased! If you look carefully at the range of floating-point numbers that rand can produce, you will find that it cannot produce the minimum or maximum number in the nominal range, and that introduces a bias to the numbers.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 10월 24일
With careful programming the bias can be overcome if the range of numbers is 2 3 5 53 157 1613 2731 8191 or any product of those used no more than once each.

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

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by