random numbers can be divided b

2 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2019-6-15
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 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by