Matlab help requesting user input and random integers
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Samayochita
el 27 de Feb. de 2025
Editada: Samayochita
el 27 de Feb. de 2025
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 comentarios
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!