Asked • 04/23/19

creating random numbers that favor smaller numbers?

say i generated a set of random numbers and put them into an array, (pre-sorted for simplicity) i'll use javascript to show the math: var vals = new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,...,10000); then in a loop, i created a random number to serve as an index: for(i=0;i<10000;i++){ var random_index = Math.floor(Math.random() * 10000); var result = vals[random_index]; } if you looked at this output on any kind of graph, the results (with enough iterations through that loop, will look pretty random and balanced) what I want, is for the results of each access to favor smaller numbers, which incidentally here is array elements with a lower index. for a visual example, imagine you're trying to plot on a map where the fragments of a firework fell. most of those fragments would fall randomly within a vicinity but have a heavier concentration towards the middle. that's a bit of an over-complicated example since it's taking another dimension into account and uses physics to achieve the result, but it's the same principal. what operation should i perform on the random_index variable to make it 'favor' smaller numbers?

1 Expert Answer


Patrick B. answered • 07/13/19

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.