Help With Homework Question
古いコメントを表示
"In a game of bingo the numbers 1 to 99 are drawn at random from a bag. Write a script to simulate the draw of the numbers (each number can be drawn only once), printing them ten to a line."
I've been trying to answer this. I believe I'm suppose to use a for loop and rand. Thank you!
回答 (1 件)
Image Analyst
2016 年 11 月 28 日
編集済み: Image Analyst
2016 年 11 月 28 日
Hint, to get a list of all 99 numbers, randomized, without repeats from a list of 1-99:
numbers = randperm(99)
Then, to simulate draws of 10 numbers, you just need to get elements 1-10, 11-20, 21-30, etc. for however many draws of 10 that you want to do.
5 件のコメント
Gregory Shoemake
2016 年 11 月 28 日
Walter Roberson
2016 年 11 月 28 日
No, you need to randperm() all of them at once, but then you can print them 10 per line. However, you have the problem that you have 99 numbers to be printed 10 per line, which is one number short from 10 rows of 10.
Gregory Shoemake
2016 年 11 月 28 日
Walter Roberson
2016 年 11 月 28 日
The question is not possible to solve in the form stated. You have only 99 values but you must print 10 per line. One or more lines would have to come out short, but that is not permitted with the wording you presented. You are going to have to fail the homework question, as is everyone else.
Image Analyst
2016 年 11 月 28 日
"the numbers that are drawn can't repeat." They don't , with randperm(). Perhaps you were thinking of randi() where the numbers are random and can repeat, or be missing. That's specifically why I used randperm() which essentially just shuffles/scrambles the order but each number is in there once and only once.
You can print out 10 at a time for nine draws of 10. The last draw will have only 9 in it, unless you put some back in. The homework question is valid only for up to 9 draws of 10. Any more than that you will run out of chips/numbers/balls. For example with 99 chips, you can't have a thousand draws of course. You have to assume that the number of draws will be 9 or less. It doesn't make sense otherwise.
カテゴリ
ヘルプ センター および File Exchange で Board games についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!