Shuffle with random number in Java

Description

The following code shows how to shuffle with random number.

Example


//from   w ww .j a  v  a  2 s .  c o  m
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class Main {
  public static void main(String args[]) {
    String simpsons[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer",
        "Maggie", "java2s.com" };
    List list1 = Arrays.asList(simpsons);
    List list2 = Arrays.asList(simpsons);
    Random rand = new Random(100);
    Collections.shuffle(list1, rand);
    Collections.shuffle(list2, rand);
    System.out.println(list1);
    System.out.println(list2);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization