How to create random integers within a specific range?

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 Answer



0



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));

admin

32

Your Answer

1 Answer

0

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));

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy