Trying to make a casino fraud
Show older comments
Good morning,
I'm working on a code for a loaded die but I'm not able to continue, since I now the modification should be done in the line for the rand function, meaning when I'm getting an outcome. This is my code:

Like I said, I believe the modification to get half of the time a six should be done in the line where I get the outcome (numbers from 1 to 6) but I'm not sure if that's right or no. Does anyone know how the casino fraud works? My code is about that, tricing a die.
Accepted Answer
More Answers (1)
Walter Roberson
on 11 Nov 2020
Use randsample() with weights.
Or construct a vector in which each value appears a number of times according to its relative weight, and do a random selection from that. For example if you had heads (1) and tails (2) and you wanted tails to come up 55 % of the time, then:
v = [ones(1,9), 2*ones(1,11)]
v(randi(20))
11/20 of the time is 55%
4 Comments
Marina Suá
on 11 Nov 2020
Your code starts out generating a single random integer. By that time, the probability is already set, and all you could do is fix-up results with more randomness. For example,
N = 1000;
Y = randi(6, 1, N);
mask = Y ~= 6;
Y(mask & rand(1,N) <= 2/5) = 6;
histogram(Y)
The code I presented earlier does things a different way: it creates a distribution that can be drawn from uniformly, but repeats elements to be drawn from in a way that the probability of selection of any particular value is the desired weight.
Marina Suá
on 11 Nov 2020
Walter Roberson
on 11 Nov 2020
randi(6, 1, N) is similar to ceil(rand(1,N)*6)
Categories
Find more on Uniform Distribution (Continuous) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!