randi function pair with logic operation

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

Ameer Hamza
Ameer Hamza 2020년 3월 7일
Can you show any code which you tried, and you are facing some issue?
For user input try input function: https://www.mathworks.com/help/matlab/ref/input.html
For printing on MATLAB console try fprintf function: https://www.mathworks.com/help/matlab/ref/fprintf.html
For generating uniformly distributed random number try rand function: https://www.mathworks.com/help/matlab/ref/rand.html
For game logic use for and while loops with if-else constructs:
Ugur Sahin
Ugur Sahin 2020년 3월 7일
I couldnt try any code. And also ı have no idea abou how random function work so ı need a function it can choose any output randomly.
randsample({'H', 'T'}, 10, true)
This relies on the statistics toolbox.
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

질문:

2020년 3월 7일

댓글:

2020년 3월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by