Help With Homework Question
Show older comments
"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!
Answers (1)
Image Analyst
on 28 Nov 2016
Edited: Image Analyst
on 28 Nov 2016
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 Comments
Gregory Shoemake
on 28 Nov 2016
Walter Roberson
on 28 Nov 2016
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
on 28 Nov 2016
Walter Roberson
on 28 Nov 2016
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
on 28 Nov 2016
"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.
Categories
Find more on Board games 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!