# Random specified numbers.

1 view (last 30 days)
Eivind Jamessen on 21 Feb 2020
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?

Giuseppe Inghilterra on 21 Feb 2020
Hi,
you can use randsample matlab function. (Reference: https://www.mathworks.com/help/stats/randsample.html).
y = randsample(n,k,true,w);
where:
• 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.
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.

Eivind Jamessen on 21 Feb 2020
I just can't understand what you mean by weights with a vector. How can i decide that 20 will be more weighted? Example?
e.g.
x = 1:100;
w = exp( -( x - 20 ).^2 / 1000 );
w = w / sum( w );
Giuseppe Inghilterra on 21 Feb 2020
Adam's example is a good one to follow in order to create in a easy and fast way weight vector.