Generate random numbers with specific mean
显示 更早的评论
I want to generate matrix 4*4 of random integer values from 0 to 255, i used randi([0 255],4) but i want to generate it with specific mean for example 200 so i used:
z = randi([0 255],4)
z = z + (200 - mean2(z))
that did fix mean value but it could change min and max value of integers, How can i fix it ??!
2 个评论
There are an infinite number of ways to generate random integers that have the following properties:
- max = 255
- min = 0
- mean = 200
For example,
N = 1000000;
p = 200/255;
x = 255 * (rand(N,1) < p);
mean(x) % Will be equal to 200, within sampling error
figure
histogram(x)
This distribution obeys the rules you have told us. And, as I said, there are infinite others. You need more specificity on the distribution.
Amr Ayman
2023-5-8
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
