Java Random randomShort()

Here you can find the source of randomShort()

Description

Generates a random word, manipulating an internal seed which is initially set to the system time.

License

Creative Commons License

Return

a random word

Declaration

public static short randomShort() 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    private static long seed = System.nanoTime(), rand = 0;

    /**/*  w  w  w.  ja  v a  2 s .c o m*/
     * Generates a random word, manipulating an internal seed which is initially set to
     * the system time.
     * 
     * @return a random word
     */
    public static short randomShort() {
        if (rand == 0) {
            seed ^= seed << 21;
            seed ^= seed >>> 35;
            seed ^= seed << 4;
            rand = seed;
        }
        final short s = (short) (rand & 0xffffL);
        rand >>>= 16;
        return s;
    }
}

Related

  1. randomProbability(double probability)
  2. randomPseudo()
  3. randomRange(int end)
  4. randomScalingFactor()
  5. randomSeed()
  6. randomSign()
  7. randomSimpleId()
  8. randomSleep()
  9. randomStateAbbr()