Java Random Number randperm(int number)

Here you can find the source of randperm(int number)

Description

randperm

License

Apache License

Declaration

public static int[] randperm(int number) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {

    public static int[] randperm(int number) {

        int[] array = new int[number];
        for (int i = 0; i < number; i++)
            array[i] = i;//  ww w  . j a va 2 s.c o  m

        int index, temp;
        Random random = new Random();
        for (int i = number; i > 1; i--) {
            index = random.nextInt(i);
            temp = array[i - 1];
            array[i - 1] = array[index];
            array[index] = temp;
        }

        return array;
    }
}

Related

  1. getSerialNumber(int length)
  2. getTenByteNumber()
  3. randomHexNumber(final int length)
  4. randomNumber(int length)
  5. randomNumber(int min, int max, Random r)