Java AtomicLong randomSeed()

Here you can find the source of randomSeed()

Description

Returns a random seed generated by taking a unique increasing long, adding System#nanoTime() and scrambling the result using the finalisation step of Austin Appleby's <a href="http://sites.google.com/site/murmurhash/">MurmurHash3</a>.

License

Open Source License

Return

a reasonably good random seed.

Declaration

public static long randomSeed() 

Method Source Code


//package com.java2s;
/*       //from www.ja v  a 2 s .  c o  m
 * DSI utilities
 *
 * Copyright (C) 2002-2014 Sebastiano Vigna 
 *
 *  This library is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as published by the Free
 *  Software Foundation; either version 3 of the License, or (at your option)
 *  any later version.
 *
 *  This library is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.util.concurrent.atomic.AtomicLong;

public class Main {
    private static final AtomicLong seedUniquifier = new AtomicLong();

    /** Returns a random seed generated by taking a unique increasing long, adding
     * {@link System#nanoTime()} and scrambling the result using the finalisation step of Austin
     * Appleby's <a href="http://sites.google.com/site/murmurhash/">MurmurHash3</a>.
     * 
     * @return a reasonably good random seed. 
     */
    public static long randomSeed() {
        long seed = seedUniquifier.incrementAndGet() + System.nanoTime();

        seed ^= seed >>> 33;
        seed *= 0xff51afd7ed558ccdL;
        seed ^= seed >>> 33;
        seed *= 0xc4ceb9fe1a85ec53L;
        seed ^= seed >>> 33;

        return seed;
    }
}

Related

  1. joinThreads()
  2. lock()
  3. max(AtomicLong x, long y)
  4. nanoTime()
  5. printProgress(final AtomicLong value)
  6. removeCustomTime()
  7. resetURICounter()
  8. runThread(Runnable r)