Random array from given array

Hi there,

Hope to be in the right forum, please excuse me if I am not...

Also sorry if my title is not very clear, but I don't know how to tell :

Let's say I have a given array :
[a,b,c,d,e,f,g,h,i,j,...........x,y,z]

I need from this a new random array with a given number of values, let's say I want to extract 10 random values, which would give for example :
[a,a,r,t,s,s,u,x,y,y]

Can anyone tell me how to achieve this ? Please note I have strictly no skills in js yet, my goal is to create an event which would create this random array and store this in a variable (doesn't need to be persistent) in order to use in later in another event.

Hope I'm clear enough, and hope someone can help me ! Thanks in advance for your help !
you create a loop, set it to repeat 10 times (or however many random values you want), then generate a random number, and use that number to push one of the values from the given array into the 'random' array. Since you didn't specify that it couldn't use the same value twice (and in fact, your example shows this happening specifically), it's actually quite easy to do this.

Code:
var randomArray = []
for (i = 0; i < 10; i++){
 var rando = Math.randomInt(OriginalArray.length)
 randomArray.push(OriginalArray[rando])
}
Thanks for your quick reply !

Indeed, values can be picked up twice (or more). But I forgot to tell my values in the first array don't always follow each other :
[1,2,6,12,46,..........]

Also, in the piece of code you show, the name of the variable storing the final array is randomArray right ? So I can use this variable in an event that's it ? (sorry for those basic questions but I'm really noob at this.)

Oh, and is it possible to display the arrayin a text box ? Maybe with \V[myarray] ?
Input the array into a variable and then you can.
I'm really ashamed to say that, but I have no idea about how to do that. As I said before, I really have no skills in javascript (but I love to learn).
Simply add
Code:
$gameVariables.setValue(1, randomArray);
at the end of the code provided in the second post.
Pretty sure I'm far away from the result :

upload_2019-9-16_23-5-50.png


Still returning 0.
Also how can the code choose from given values ?
(and thanks for your patience...)

Nevermind I figured my mistake.

Thanks for your precious help ! It works ! (I just forgot to create my initial array...)
Hum... I'm back mith my stupid questions.

I have another piece of code saying this :

$cardOpponent().deck.cards = [248, 248, 302, 302, 320, 320, 360, 360, 374, 374, 393, 393, 449, 449, 463, 463, 500, 500, 516, 516, 538, 538, 600, 600, 624, 624, 649, 649, 659, 659, 683, 683, 712, 712, 751, 751, 775, 775, 792, 792];

How can I say "use randomArray instead of predefined array" ? I tried several ways but I may have a syntax problem, I don't know how to write it.

My randomArray is now programmed to put 40 random values in the array.

I tried $cardOpponent().deck.cards.push(randomArray); but it doesn't work.

Edit : ok, found it.

Original thread: https://forums.rpgmakerweb.com/threads/random-array-from-given-array.113367/