Here you can find the source of randomBases(int n)
Parameter | Description |
---|---|
n | the length of the base string |
public static String randomBases(int n)
//package com.java2s; /*/*from w w w .j av a 2 s.c o m*/ * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/ */ public class Main { /** * Generate a string of random bases of length n. * @param n the length of the base string * @return the base string */ public static String randomBases(int n) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int pick = (int) Math.floor(Math.random()); switch (pick % 4) { case 0: sb.append("T"); break; case 1: sb.append("C"); break; case 2: sb.append("A"); break; case 3: sb.append("G"); break; } } return sb.toString(); } }