Question: I have seen this question [answered](https://stackoverflow.com/questions/5416567/random-selection) here, but I have an additional question that is related.

Im trying to achieve:
=====================

the same thing, but, with the *output being a selection of more than 1 number*, the above works fine if you only want a single value returned.

How can I return (x) amount of outputs #7 in this case into a new var or array ...? Some guidance on best practice will also be appreciated ;) 

**Thanks a bunch....**
----------------------

---

Just for fun,
Objective:

Create a teeny weenie web App that returns 7 variable numbers in a range [ 1 - 49 ] into an array.
`
Think return a list of Lotto Numbers
Create new array from selection using \_underscore.js [Sample function]

\*\*\*\* I know this is easier, but im trying to get an understanding 
of using Vanilla JS to accomplish this 

\_.sample([1, 2, 3, 4, 5, 6], 3); => [1, 6, 2]

---

```
var getLoot = Array.from(Array(50).keys()) // Create array of 49 numbers.
console.info(getLoot);
var pick = getLoot[Math.floor(Math.random() * getLoot.length)];

pick; 

```

// pick returns a single which is fine if you want a single but, ..
// I want something like this : 

```
var pick = function() {
    // code that will return 7 numbers from the array into a new Array
    // will randomize every time pick is called...
}

```

Answer: 
If you want to return more than just 1 value you can store your results into a data structure like [an array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array). Here is a solution to the problem
assuming you can pass in your array of 50 numbers into the `pick()` funciton.:

```
var getRandomArbitrary = function(min, max) {
    return Math.floor(Math.random() * (max - min) + min);
}

var pick = function(fiftyNumberArray, numberOfValuesWanted) {
    var randomNums = [];
    for(var i = 0; i < numberOfValuesWanted; i++) {
        randomNums.push(
            fiftyNumberArray[getRandomArbitrary(0, 50)]
        );
    }
    return randomNums;
};

var fiftyNumbers = [] // <- set your array of fifty numbers
pick(fiftyNumbers, 7);

```

Javascript's `Math.random()` will return a value in between 0 and 1 (exclusive). So to get an index scaled up to the correct value to look into your array, you would want to multiply that by the formula `(max - min) + min`
This is probably what you want.

```
$(function() 
{
    var lol = [1,4,5,6,7,8,9];
    function getPart(array,number)
    {
        var part = [],
            index;
        while(true)
        {
            if(part.length == number)
            {
                break;
            }
            index = $.random(0,part.length);
            part.push(lol.splice(index,1));

        }
        return part;
    }
});
$.random = function(min,max,filter)
{

    var i,
        n = Math.floor(Math.random()*(max-min+1)+min);
    if(filter != undefined && filter.constructor == Array)
    {
        for(i=filter.length-1;i>-1;i--)
        {
            if(n == filter[i])
            {
                n = Math.floor(Math.random()*(max-min+1)+min)
                i = filter.length;
            }
        }
    }
    return n;
}

```