How to create random integers within a specific range?

User ForumHow to create random integers within a specific range?
admin Staff asked 4 years ago

The rndi function creates random integers, but I need to create a vector of random integers within a specific range such as between 1 and 30. How can I do this in GAUSS?

1 Answers
admin Staff answered 4 years ago

You can create random integers with a range of [1, maxRange] by multiplying a vector of uniform random numbers by maxRange and then applying the ceil function to round these numbers up to the next whole number. For example to create 40 random integers between 1 and 30, you could:

r = ceil(30 * rndu(40, 1));