can I generate random no. from 0 to 10E5, but the condition is ?

2 次查看(过去 30 天)
I want to generate random no. between 0 to 100E3 but the no. will be in increasing order
rand(1,5)
ans = 1×5
0.1125 0.7463 0.9112 0.0562 0.8338
like this i want to generate but from 0 to 10E5 and 1-cross-80 elements.

回答(1 个)

Torsten
Torsten 2022-8-31
编辑:Torsten 2022-8-31
numbers = sort(100e3*rand(1,80),'ascend')
numbers = 1×80
1.0e+04 * 0.4103 0.5521 0.6855 1.0094 1.0585 1.3153 1.3774 1.4370 1.4387 1.7162 1.8382 1.8413 1.8864 1.9604 2.1014 2.1396 2.1568 2.3704 2.5154 2.6819 2.9373 3.2460 3.4493 3.4535 3.6238 3.6271 3.7908 3.7910 3.9757 4.1136
or
numbers(1) = 100e3*rand;
for i = 2:80
numbers(i) = numbers(i-1) + (100e3 - numbers(i-1))*rand;
end
numbers
numbers = 1×80
1.0e+05 * 0.7274 0.8968 0.9326 0.9548 0.9887 0.9971 0.9994 0.9996 0.9998 0.9999 0.9999 0.9999 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
depending on what you mean by "random" and "ascending".

类别

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