Embedded code for Randi function.it generates 625 arrays to some values, I want to know why it is generated 625 arrays of random values in initial function

2 views (last 30 days)
leena on 30 May 2024
Edited: Manikanta Aditya on 30 May 2024
y = randi([0, 11],uint32)
Ganesh on 30 May 2024
I assume you mean that it creates an array with 625 values. I also assume that you do not intend to use the function "uint32()".
There is likely a variable in workspace with the name uint32 with a value of 25.
When you provide a single size, here uint32, to "randi()", it creates a matrix of size uint32*uint32, hence you get an array with 625 values. Reading the documentation related to the function "randi()" thoroughly will certainly help.

Manikanta Aditya on 30 May 2024
Edited: Manikanta Aditya on 30 May 2024
Hi @leena,
The randi function in MATLAB generates uniformly distributed random integers in a specified interval. The syntax you’ve used, randi([0, 11],uint32), is not correct as the second argument to randi should be the size of the array you want to generate.
If you want to generate a 625-element array of random integers between 0 and 11, you should use:
y = randi([0, 11], [1, 625]);
disp(y);
Columns 1 through 30 4 3 2 5 2 1 4 2 0 9 5 3 3 2 5 6 7 7 0 6 10 0 4 10 5 9 2 6 11 11 Columns 31 through 60 9 3 9 0 11 7 6 1 3 6 4 6 2 1 11 4 9 10 2 9 11 8 3 11 7 0 5 8 5 0 Columns 61 through 90 4 10 7 10 1 1 9 7 10 9 9 3 9 4 11 4 10 4 6 11 5 5 8 2 6 2 5 3 2 5 Columns 91 through 120 3 0 0 0 2 0 10 9 7 11 2 3 7 7 3 8 0 9 6 8 5 0 2 0 0 10 5 7 6 10 Columns 121 through 150 0 3 5 1 6 7 8 9 5 1 3 2 8 7 8 6 4 3 8 1 5 7 3 4 1 5 1 6 6 4 Columns 151 through 180 4 11 7 10 4 10 7 10 7 11 3 2 0 7 5 4 7 2 9 1 8 7 8 7 11 5 8 11 7 10 Columns 181 through 210 9 2 4 6 0 6 4 11 4 2 11 8 5 8 9 4 5 11 11 11 6 7 5 11 11 0 4 11 10 8 Columns 211 through 240 6 6 11 2 2 1 11 1 9 9 10 6 11 10 9 8 9 9 2 5 10 11 4 6 3 0 7 11 11 4 Columns 241 through 270 4 2 3 2 6 7 3 4 10 6 9 3 4 3 1 6 7 1 11 6 8 6 10 5 10 9 2 6 6 1 Columns 271 through 300 6 1 10 9 6 3 5 2 1 1 11 11 11 0 10 11 2 1 4 0 6 4 10 3 1 11 6 11 6 9 Columns 301 through 330 4 6 6 11 0 3 5 0 4 6 7 11 4 11 8 8 4 4 9 7 9 8 5 5 7 2 0 9 0 7 Columns 331 through 360 1 9 0 4 8 3 3 5 11 11 6 4 4 0 9 2 9 3 11 6 0 0 1 2 6 2 1 10 3 5 Columns 361 through 390 1 8 2 11 5 11 2 3 4 6 9 6 9 3 2 7 1 10 3 11 3 5 1 6 5 9 6 10 0 5 Columns 391 through 420 4 7 0 4 7 5 11 2 10 9 6 9 6 0 1 11 0 3 5 7 6 0 0 8 1 1 8 0 9 9 Columns 421 through 450 6 10 6 10 6 4 7 7 3 10 9 4 10 0 5 3 6 5 8 11 3 0 10 1 4 8 7 3 11 0 Columns 451 through 480 7 2 1 11 10 4 4 11 8 7 0 7 3 10 9 11 8 10 8 1 1 9 7 3 10 4 7 5 5 8 Columns 481 through 510 1 1 7 4 8 9 5 1 8 10 10 3 7 10 10 10 10 8 6 3 11 6 2 9 7 2 9 9 0 2 Columns 511 through 540 4 0 8 1 7 9 4 0 9 9 8 9 3 11 5 10 11 8 11 4 9 2 5 0 10 2 7 11 11 11 Columns 541 through 570 10 8 3 3 0 8 7 1 4 11 9 8 6 2 4 10 8 8 1 1 1 7 0 3 1 6 3 8 2 9 Columns 571 through 600 9 6 3 5 10 4 3 3 7 6 7 3 6 3 5 10 0 0 0 11 3 2 6 7 9 4 8 0 4 6 Columns 601 through 625 5 5 9 5 3 5 2 6 0 3 11 7 1 7 3 5 1 9 2 2 11 3 5 1 11
This will create a 1x625 matrix y with each element being a random integer between 0 and 11.
If you’re seeing 625 arrays being generated, it’s likely due to a loop or other repeated call to randi in your code and also it might be due to a loop or function call not shown in the snippet you provided. Ensure that the context of the function call is appropriate and not wrapped in unnecessary loops unless required by your application.
I think this clarifies!