How can I choose non-repeating values with a probability of 90% and 10% ?
1 view (last 30 days)
Show older comments
giancarlo maldonado cardenas
on 17 Feb 2022
Commented: Wasseem Khardawi
on 19 Feb 2022
Hello friends, how can I choose values that do not repeat with a probability of 90% and 10%?
let me explain myself better.
For example I have a vector:
vector = [43 19 63 60 19 27 6]
So what I have done so far with my algorithm is that if the numbers that are inside the vector are not repeated, I assign a binary code of "1", on the other hand, if any number inside the vector is repeated, I assign a binary code of "0". ", as can be seen in the image below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/898365/image.png)
now I want to solve the following problem, that, if the numbers within the vector are not repeated, they have a 90% probability of assigning the binary code "1" and a 10% probability of assigning the binary code "0", on the other hand if the numbers within the vector are repeated with a 100% probability of being assigned the binary code "0".
for example:
taking the variable :
vector = [43 19 63 60 19 27 6]
numbers that are not repeated we have 43,63,60,27 and 6.
then it would have to be randomly assigned the binary code "1" with a 90% probability and the binary code "0" with a 10% probability.
taking into account that the probability is assigned randomly
then the result would be something like this.
I touch 90% to 43 so it is assigned the binary code "1"
I touch 90% to 63 so it is assigned the binary code "1"
I touch 10% to 60 so it is assigned the binary code "0"
I touch 90% to 27 so it is assigned the binary code "1"
I touch 90% to 6 so it is assigned the binary code "1"
Now the repeated numbers of the vector are 19,19.
then with 100% the binary code of "0" is assigned
19 is assigned the binary code "0" >> with 100%
19 is assigned the binary code "0" >> with 100%
in the end my matrix would look like this
43 "1"
19 "0"
63 "1"
60 "0"
19 "0"
27 "1"
6 "1"
thank you very much in advance
1 Comment
Accepted Answer
Voss
on 18 Feb 2022
To generate a number that has value 1 with 90% probability and value 0 with 10% probability, you can use randi() to generate a random integer between 1 and 10, then use the condition that the integer is greater than 1. It will be greater than 1 90% of the time (so the condition will be true) and (less than or) equal to 1 10% of the time (and the condition will be false). Convert the condition from logical to double, and you have your number(s). A demonstration with 10000 random numbers obeying this distribution:
x = double(randi(10,1,10000) > 1);
nnz(x)
0 Comments
More Answers (0)
See Also
Categories
Find more on LTE Toolbox 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!