Matlab help requesting user input and random integers
11 ビュー (過去 30 日間)
古いコメントを表示
Write a program that will prompt the user for minimum and maximum integers, and then another integer that is the user’s choice in the range from the minimum to the maximum. The script will then generate random integers in the range from the minimum to the maximum, until a match for the user’s choice is generated. The script will print how many random integers had to be generated until a match for the user’s choice was found.
0 件のコメント
回答 (1 件)
Samayochita
2025 年 2 月 27 日
編集済み: Samayochita
2025 年 2 月 27 日
Hi Chris,
I understand that you are trying to write MATLAB code that prompts the user for minimum and maximum integers, then asks for a target number within that range. It should then generate random numbers in that range until it matches the target and display how many attempts were needed to generate this number.
You can use “rng('shuffle');” to initialize the random number generator using the current time as a seed.
Additionally, you can use “randi” function
(https://www.mathworks.com/help/matlab/ref/randi.html) to generate a random number within the given range.
Keep generating numbers in a loop until a match is found and count how many numbers were generated before finding the match and display the result.
Hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!