Filter löschen
Filter löschen

randi function pair with logic operation

3 Ansichten (letzte 30 Tage)
Ugur Sahin
Ugur Sahin am 7 Mär. 2020
Kommentiert: Walter Roberson am 7 Mär. 2020
Hi guys,
I want to prepare a program that can decide randomly on the determined lines. Such that, if I respond tail (in set of tail and head) program will decide on their line.
Heads or tails (H/T)? H
You won! Your new credit is 1010.
Heads or tails (H/T)? T
You won! Your new credit is 1010.
Heads or tails (H/T)? h
You lose! Your new credit is 960.
like that I have to pair winning function randomly with true or false on each line again.
please can you help me ?
  4 Kommentare
Walter Roberson
Walter Roberson am 7 Mär. 2020
randsample({'H', 'T'}, 10, true)
This relies on the statistics toolbox.
Walter Roberson
Walter Roberson am 7 Mär. 2020
Hint:
rand() generates values between 0 and 1 (exclusive) on a uniform random sampling basis.
If you have a random number between 0 and 1, and you compare that random number to (probability percentage divided by 100) then the event is true with the given probability. rand() <= (37/100) would be true with 37% probability.
Once you have a value that is either true (1) or false (0) then you can convert that into 'H' or 'T' in any of several ways.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by