All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nextflow.util.Rnd.groovy Maven / Gradle / Ivy

Go to download

A DSL modelled around the UNIX pipe concept, that simplifies writing parallel and scalable pipelines in a portable manner

There is a newer version: 24.08.0-edge
Show newest version
package nextflow.util

import java.security.SecureRandom

/**
 * Rnd key generator
 *
 * @author Paolo Di Tommaso 
 */
class Rnd {

    private static final BigInteger B = BigInteger.ONE.shiftLeft(80); // 2^64

    private static final SecureRandom random = new SecureRandom();

    private Rnd() {}

    /**
     * Generate random key base62 encoded ie. containing only [0-9a-zA-Z] characters
     * guaranteed to be unique.
     *
     * Tested with 100 mln iteration -> 0 collision
     *
     * @return A random generated alphanumeric between 9-14 characters
     */
    static String key() {
        byte[] buffer = new byte[10]
        random.nextBytes(buffer)
        def big = new BigInteger(buffer)
        if (big.signum() < 0) {
            big = big.add(B)
        }

        return Base62.encode(big)
    }

    static String hex() {
        byte[] buffer = new byte[10]
        random.nextBytes(buffer)
        return buffer.encodeHex()
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy