How to randomly shuffle an array in Java ?.

preview_player
Показать описание
► CLICK TO DOWNLOAD COMPLETE SOURCE CODE -
Рекомендации по теме
Комментарии
Автор

After multiple days of research, I finally found what I was looking for. Real java random video. Thanks.

gervinho
Автор

Thank you! I was having difficulty grasping exactly how to create a program that implements random shuffling of array elements, and my course textbook does not provide any detailed examples. Great video :)

kellyh.
Автор

public class Test
{
public static void shuffle(Object[] array)
{
int noOfElements = array.length;
for(int i = 0; i < noOfElements; i++)
{
int s = i +(int)(Math.random() * (noOfElements - i));
Object temp = array[s];
array[s] = array[i];
array[i] = temp;

}
}

public static void main(String[] args)
{
String[] strofCharacters = {"A", "B", "C", "D", "E"};
Test.shuffle (strofCharacters);
for(int i=0; i < strofCharacters.length; i++)
[i] + " ");
}
}

Me_Myself_
Автор

giving error on randomarray.shuffle(array name) vs code, even when the code is proper🤔

it was solved but didn't understood : A RandomArray;
A.schuffle(array name);

Baljeet-kh
Автор

dat microsoft sam voice, good vid, but id prefer your indian accent 

danoreilly
Автор

sometimes the i + (int)(Math.random() * (size -1)); generates an number outofbounds throwing that erro, i removed the (i + part and it works

Half__
Автор

Can a Question be a string character? Thanks

TheFraternalHouse
Автор

wait, in the ( for ) loop you were printing the original array, not the Random Array.. i don't understand how did that work?!!?

smartandfunny
Автор

why the dislikes? Does this not work lol

PortgasDAce-kpwk