I read on MATLAB's docs that they use a Mersenne Twister for their rand() and randi() functions.
I wrote some sample code to test randomness:
rng('shuffle');
rand_arr = zeros(10, 10);
for i=1:10
rand_arr(i,:) = randi(800, 1, 10);
end
uncollided = 0;
for p=1:10
if length(rand_arr(:,p)) == length(unique(rand_arr(:,p)))
uncollided = uncollided + 1;
end
end
disp(uncollided/10);
The number of uncollided sets for a set 10 numbers ended up being 95% sets on average, which seems to be too low. It gets worse as I decrease the universe of randi(). I thought a Mersenne Twister would have better values. Is there a more "random" generator available?
I'm using MATLAB v2017.
Thanks.
Aucun commentaire:
Enregistrer un commentaire