MV Splicing an Array

I'm pulling numbers from an array and once the number is pulled it is removed from the array.

This is my code:

Code:
$gameVariables.setValue(453, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52]);

$gameVariables.setValue(454, $gameVariables.value(453).splice(Math.floor(Math.random() * $gameVariables.value(453).length), 1))

Now this works fine but now I'd like to be able to only pull from part of the same array.
So how would I go about only pulling from say numbers 1 - 12?
Unless I've misunderstood, you can simply change the range of the random index, e.g.
JavaScript:
var arr = $gameVariables.value(453);               // array of values
var r = Math.randomInt(Math.min(12, arr.length));  // random index
$gameVariables.setValue(454, arr.splice(r, 1));
I think this should randomly pick one of the first X remaining entries in the array, where X is 12 or the array length, whichever is smaller~
@caethyril Thanks for the response!

I need to make sure that it can't pull anything except 1 thru 12 in the array.
So if I already pulled 1 - 12 out of the array it won't take any other numbers from the array.
What you need is arr.indexOf(12), something like this:

JavaScript:
var arr = $gameVariables.value(453);               // array of values
var n = arr.indexOf(12);
if(r >= 0) {
var r = Math.randomInt(Math.min(n, arr.length) - 1);  // random index
$gameVariables.setValue(454, arr.splice(r, 1));
}
@Solar_Flare That's what I needed thanks so much!
Oh I see! @Solar_Flare's solution looks mostly good, but note that Math.randomInt(X) will produce a random integer in the range [0, X-1]. You may want to use this line instead:
JavaScript:
var r = Math.randomInt(Math.min(n + 1, arr.length));
E.g. if the value 12 is the 4th value remaining in the array then n will be 3 because array indexing starts at 0.
So to include the value 12 you'd need a random integer from 0~3 inclusive.
Thus you can use Math.randomInt(4), i.e. Math.randomInt(n+1). 🙂

Happy RPG Making~ 😂
@caethyril Good catch, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/splicing-an-array.129956/