0

I have an array of string elements like this [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O]

I want to split this into n arrays, where n is chosen randomly, and the elements in each new array are also chosen randomly.

For example if n=4, and the original array is [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O], I might get

[C,E,G,A]
[I,B,O,L]
[H,F,J,N]
[D,K,M]

How can I do this?

jscs
  • 63,694
  • 13
  • 151
  • 195
  • Do you want your sub arrays to have same number of elements inside them? Or, do you want to have x number of arrays where each of them can have variable number of elements inside them? – nayem May 04 '17 at 13:03
  • Hello nayem, yes i want to have same number of elements inside them. –  May 08 '17 at 08:29
  • Well, you should first `shuffle` your original array ( follow [this](http://stackoverflow.com/a/56656/3687801) ) and then you have to `split` your `shuffled array` ( follow [this](http://stackoverflow.com/a/6852105/3687801) ) – nayem May 08 '17 at 10:31
  • thx. its working fine. –  May 10 '17 at 07:21

0 Answers0