how to generate 10 random numbers each between 1 to 100 then 101 to 200 etc. till 1000?
54 views (last 30 days)
Show older comments
total no. generated should be 100. 10 between 1 to 100 then next 10 between 101 to 200 etc.
2 Comments
Answers (3)
Jan
on 28 Jun 2017
Edited: Jan
on 28 Jun 2017
Perhaps:
X = randi([0, 99], 10, 10) + (1:100:1000); % requires Matlab >= 2016b
With older versions:
X = bsxfun(@plus, randi([0, 99], 10, 10), 1:100:1000);
If floating point numbers are wanted, see KSSV's method:
X = (1 + 99 * rand(10, 10)) + (1:100:1000);
Again: for older versions:
X = bsxfun(@plus, (1 + 99 * rand(10, 10)), 1:100:1000);
2 Comments
Jan
on 28 Jun 2017
@Yash Singh: The code for older versions is included in this answer, too. For integer values use the 2nd of the 4 shown methods.
KSSV
on 28 Jun 2017
To generate 10 random number between 1 and 100 use:
a = 1;
b = 100;
r = (b-a).*rand(10,1) + a;
0 Comments
Linus Antonio Ofori Agyekum
on 22 May 2018
how do i generate 1000 point random integers with 4 levels?
1 Comment
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!