- n is the maximum integer random value generated;
- k is number of random values that you want generate;
- w is weigth vector that contains n weights.
Random specified numbers.
1 次查看(过去 30 天)
显示 更早的评论
Hi, I want to print random numbers from 1 to 100, but i want to specifiy that most of the numbers should be around 20. In other words, it is most likely to get 20, but other numbers can also occur. Is this possible?
0 个评论
回答(1 个)
Giuseppe Inghilterra
2020-2-21
Hi,
you can use randsample matlab function. (Reference: https://www.mathworks.com/help/stats/randsample.html).
y = randsample(n,k,true,w);
where:
In your case n = 100 and you must define w vector with 100 weights (value 20 will be more weighted) such that weight sum is 1.
Hope this helps.
3 个评论
Giuseppe Inghilterra
2020-2-21
Adam's example is a good one to follow in order to create in a easy and fast way weight vector.
另请参阅
类别
在 Help Center 和 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!