Tuesday, December 15, 2009

How to generate random numbers in Matlab?

I need to write a script that generates a random integer from 1-15 (using a uniform distribution with the random number generator originally set to a state of 18) and then prompt the user to enter a number from 1-15. How can i go about this? It might be easy for some people but i just cant get the random number generator to display whole numbers.





Any help would be appreciated.


ThanksHow to generate random numbers in Matlab?
x = round(15*rand)


y = input('guess 1 to 15: ')





I don't know what you mean by ';originally set to a state of 18.'; You mean the seed?





I think this may work:


rand('seed',18)


round(15*rand)





Output is 3.

No comments:

Post a Comment