Trying to make a casino fraud

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

Ameer Hamza
Ameer Hamza on 11 Nov 2020
Edited: Ameer Hamza on 11 Nov 2020
This is one way:
x = [0:0.1:0.5 1];
y = discretize(rand(1000,1), x);
Although it can be generalized, however, you can directly use randsample() from the Statistics and Machine Learning toolbox
y = randsample(1:6, 1000, true, [0.1 0.1 0.1 0.1 0.1 0.5])
You can also used this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/26003-random-numbers-from-a-user-defined-distribution in case you don't have the toolbox.

1 Comment

Thank you! But what about doing it the way I start it? Like would it be possible to define the ran() function applying the way you did it? I don't know if I'm expressing myself.

Sign in to comment.

More Answers (1)

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

So it seems like I will need to use another way to compute this exercise. This is helpful thank you aswell!!
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.
Well I'm starting working with matlab now, so you are using some commands I don't know yet. Anyway, is good to know about it. thx!
randi(6, 1, N) is similar to ceil(rand(1,N)*6)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!