1

I want to create a random array with values between 0 to 255 but without any looping value, like (0: 255) but its value is scrambled. how to do it?

output like

32, 204, 16, 92, ...
riang_a
  • 15
  • 4
  • 3
    Possible duplicate of [Is there a way in Matlab using the pseudo number generator to generate numbers within a specific range?](https://stackoverflow.com/questions/2152334/is-there-a-way-in-matlab-using-the-pseudo-number-generator-to-generate-numbers-w) – Leander Moesinger Oct 03 '17 at 15:23

3 Answers3

2

With really random and possibly repeating numbers:

randi(256,1,256)-1

Every value occuring exactly once, random permutation:

randperm(256)-1
Daniel1000
  • 779
  • 4
  • 11
0

Use the randperm function.

result = randperm(255);
Alex Taylor
  • 1,402
  • 1
  • 9
  • 15
0

I am not sure what you mean by looping but if you want a random array with values between 0 and 255 uniformly distributed you can do this:

a = floor(256*rand(1,10000));

This will give you an array with 10000 values uniformly distributed between 0 and 255

Laleh
  • 488
  • 4
  • 16