Java Random randomAlternate(char c)

Here you can find the source of randomAlternate(char c)

Description

random Alternate

License

Apache License

Declaration

public static char randomAlternate(char c) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    public static final char[] letters = { 'A', 'T', 'G', 'C' };
    public static final List<Character> letterList = Arrays.asList('A', 'T', 'G', 'C');
    public static Random rand = new Random();

    public static char randomAlternate(char c) {
        int idx = letterList.indexOf(c);
        return letters[(idx + rand.nextInt(letters.length - 1) + 1) % letters.length];
    }//  ww  w . ja  v  a  2 s  .c o  m

    public static String randomAlternate(String base, int alternateOffset) {
        StringBuilder sb = new StringBuilder(base);
        sb.setCharAt(alternateOffset, randomAlternate(sb.charAt(alternateOffset)));
        return sb.toString();
    }
}

Related

  1. random4DigitNumber()
  2. random_g729()
  3. random_g729()
  4. randomAgain()
  5. randomAlpha()
  6. randomCharacterVector(int size)
  7. RandomCode()
  8. randomCode()
  9. randomCSeq()