MATLAB: How to generate random numbers 0 and 1

random

I need to generate random numbers 0 and 1,if i use randi(1) it will be in fraction. exactly i need to generate 0 and 1 randomly???pls help

Best Answer

Try
n = 10; % However many numbers you want.
randomNumbers = randi([0, 1], [1, n])
This will give a double. If you want integers, then cast to int32.
randomNumbers = int32(randi([0, 1], [1, n]));
or use logical() if you want booleans.