random generator on level of bytes
조회 수: 9 (최근 30일)
이전 댓글 표시
I need to create a column using the randi function to generate random numbers that are divisible of 8 for bytes. Example: 512, 64, 128, 1048576.
Currently tried Data_Bytes = randi([8,1048576],8,1)
Obviously it does not give me items divisible by 8 and know I need to use the divisible(8) function but do not know how to combine the two for a successful output.
Thank you!
댓글 수: 0
채택된 답변
James Tursa
2019년 6월 20일
편집: James Tursa
2019년 6월 20일
Generate random integers and then multiply them by 8 to guarantee that the result is divisible by 8. E.g., something like:
max_value = 1048576/8;
n = 8;
Data_Bytes = randi(max_value,n,1)*8;
댓글 수: 1
John D'Errico
2019년 6월 20일
+1. The important thing to recognize is that you need to look at it from the right point of view. Instead of thinking about this as a problem of generating random numbers divisible by 8, think about generating random integers, and THEN multiply by 8. That insures the desired result.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!