Skip to main content
deleted 6 characters in body
Source Link
MAG
  • 3k
  • 15
  • 30

Your algorithm doesn't have simple uniform distribution over the !n. Your alternative do has it, is actually a known algorithm named Fisher–Yates shuffle) :.

Your algorithm doesn't have simple uniform distribution over the !n. Your alternative do has it, is actually a known algorithm named Fisher–Yates shuffle) :

Your algorithm doesn't have simple uniform distribution over !n. Your alternative do has it, is actually a known algorithm named Fisher–Yates shuffle.

deleted 188 characters in body
Source Link
MAG
  • 3k
  • 15
  • 30

Your algorithm doesn't have simple uniform distribution over the !n permutations.

To achieve that Your alternative do has it, change your code to (This is actually a known algorithm named Fisher–Yates shuffle) :

public static <E> void shuffling(List<E> list1, Random rnd){
    for(int i = list1.size(); i >= 1; i--){
        swap(list1, i - 1, rnd.nextInt(i);
    }
}

Your algorithm doesn't have simple uniform distribution over the !n permutations.

To achieve that, change your code to (This is actually a known algorithm named Fisher–Yates shuffle) :

public static <E> void shuffling(List<E> list1, Random rnd){
    for(int i = list1.size(); i >= 1; i--){
        swap(list1, i - 1, rnd.nextInt(i);
    }
}

Your algorithm doesn't have simple uniform distribution over the !n. Your alternative do has it, is actually a known algorithm named Fisher–Yates shuffle) :

Source Link
MAG
  • 3k
  • 15
  • 30

Your algorithm doesn't have simple uniform distribution over the !n permutations.

To achieve that, change your code to (This is actually a known algorithm named Fisher–Yates shuffle) :

public static <E> void shuffling(List<E> list1, Random rnd){
    for(int i = list1.size(); i >= 1; i--){
        swap(list1, i - 1, rnd.nextInt(i);
    }
}