Java Random Number getRandomNumber()

Here you can find the source of getRandomNumber()

Description

get Random Number

License

Open Source License

Declaration

public static int getRandomNumber() 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public static int getRandomNumber() {
        int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Random rand = new Random();
        for (int i = 10; i > 1; i--) {
            int index = rand.nextInt(i);
            int tmp = array[index];
            array[index] = array[i - 1];
            array[i - 1] = tmp;//from   www  . jav a 2s.c  om
        }
        int result = 0;
        for (int i = 0; i < 6; i++)
            result = result * 10 + array[i];
        System.out.println(result);
        return result;
    }
}

Related

  1. getRandomNumAndStr(int length)
  2. getRandomNumber()
  3. getRandomNumber()
  4. getRandomNumber()
  5. getRandomNumber()
  6. getRandomNumber(final int from, final int to)
  7. getRandomNumber(final int maxInt, final int minInt)
  8. getRandomNumber(int bit)
  9. getRandomNumber(int bound)