MATLAB Answers

0

random numbers can be divided b

Asked by fatima alansari on 15 Jun 2019
Latest activity Answered by Star Strider
on 15 Jun 2019
hello,
how can i generate random numbers within a range that all generated numbers can be divided by 5??
meaning:
random number = r
r%5 = 0
regards

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 15 Jun 2019
 Accepted Answer

Try this:
r5 = randi(10,1,20)*5; % Creates 20 Random Integers From 5 To 50, All Of Which Can Be Divided Evenly By 5
Test = rem(r5,5)
The ‘Test’ vector will have elements only equal to 0.
To specify a range, see: Random Integers Within Specified Interval (link).

  0 Comments

Sign in to comment.