Example usage for org.apache.commons.math3.random Well1024a nextInt

List of usage examples for org.apache.commons.math3.random Well1024a nextInt

Introduction

In this page you can find the example usage for org.apache.commons.math3.random Well1024a nextInt.

Prototype

public int nextInt(int n) throws IllegalArgumentException 

Source Link

Document

This default implementation is copied from Apache Harmony java.util.Random (r929253).

Implementation notes:

  • If n is a power of 2, this method returns (int) ((n * (long) next(31)) >> 31) .
  • If n is not a power of 2, what is returned is next(31) % n with next(31) values rejected (i.e.

    Usage

    From source file:com.milaboratory.core.io.sequence.fasta.FastaWriterTest.java

    private static SingleRead randomRead(long id) {
        Well1024a random = new Well1024a(id);
        Bit2Array seq = new Bit2Array(50 + random.nextInt(150));
        for (int i = 0; i < seq.size(); ++i)
            seq.set(i, (byte) random.nextInt(NucleotideSequence.ALPHABET.size()));
        byte[] quality = new byte[seq.size()];
        Arrays.fill(quality, SequenceQuality.GOOD_QUALITY_VALUE);
        return new SingleReadImpl(id,
                new NSequenceWithQuality(new NucleotideSequence(seq), new SequenceQuality(quality)), "id" + id);
    }
    

    From source file:com.milaboratory.core.io.util.TestUtil.java

    public static File createRandomFile(long seed, int avLinesCount) throws IOException {
        File temp = File.createTempFile("temp" + seed, "tmp");
        temp.deleteOnExit();/*from w  ww.  j  av a2  s  .  com*/
        FileOutputStream output = new FileOutputStream(temp);
        Well1024a random = new Well1024a(seed);
    
        int numberOfLines = avLinesCount + random.nextInt(10);
        for (int i = 0; i < numberOfLines; ++i) {
            StringBuilder sb = new StringBuilder();
            for (int j = (1 + random.nextInt(100)); j >= 0; --j)
                sb.append(random.nextInt(100));
            String string = sb.toString();
            byte[] bytes = string.getBytes();
            output.write(bytes);
            output.write('\n');
        }
        output.close();
        return temp;
    }
    

    From source file:com.milaboratory.core.io.sequence.fasta.FastaReaderTest.java

    private static TestItem createTestData(long seed, int readsCount, boolean withWildcards) throws IOException {
        Well1024a rnd = new Well1024a(seed);
    
        File tempFile = File.createTempFile("temp" + seed, ".fasta");
        tempFile.deleteOnExit();//from  ww w.jav  a 2 s. co  m
        FileOutputStream output = new FileOutputStream(tempFile);
    
        SingleRead[] reads = new SingleRead[readsCount];
    
        WildcardSymbol[] wildcards = NucleotideSequence.ALPHABET.getAllWildcards().toArray(new WildcardSymbol[0]);
        long id = 0;
        for (int i = 0; i < readsCount; ++i) {
            char[] seq = new char[50 + rnd.nextInt(100)];
            char[] seqExp = new char[seq.length];
    
            int qPointer = 0;
            byte[] qualityData = new byte[seq.length];
            Arrays.fill(qualityData, SequenceQuality.GOOD_QUALITY_VALUE);
            for (int j = 0; j < seq.length; ++j) {
                seq[j] = seqExp[j] = NucleotideSequence.ALPHABET.symbolFromCode((byte) rnd.nextInt(4));
                if (j != 0 && j != seq.length - 1 && ((4 * j) % seq.length == 0) && rnd.nextBoolean()) {
                    //next line for sequence
                    seq[j] = seqExp[j] = '\n';
                    --qPointer;
                } else if (withWildcards && j % 5 == 0) {//wildcard
                    WildcardSymbol wildcard = wildcards[rnd.nextInt(wildcards.length)];
                    if (NucleotideSequence.ALPHABET.codeFromSymbol(wildcard.getSymbol()) == -1) {
                        seq[j] = wildcard.getSymbol();
                        seqExp[j] = NucleotideSequence.ALPHABET
                                .symbolFromCode(wildcard.getUniformlyDistributedSymbol(id ^ (j + qPointer)));//as used in FastaReader#getSequenceWithQuality(..)
                        qualityData[j + qPointer] = SequenceQuality.BAD_QUALITY_VALUE;
                    }
                }
            }
            String description = ">seq" + i;
            String sequenceString = new String(seq);
            output.write(description.getBytes());
            output.write('\n');
            output.write(sequenceString.getBytes());
            output.write('\n');
    
            reads[i] = new SingleReadImpl(id,
                    new NSequenceWithQuality(new NucleotideSequence(new String(seqExp).replace("\n", "")),
                            new SequenceQuality(Arrays.copyOfRange(qualityData, 0, seq.length + qPointer))),
                    description.substring(1));
            ++id;
        }
        output.close();
    
        return new TestItem(tempFile, reads);
    }