Java tutorial
//package com.java2s; /******************************************************************************* * $Id: $ * Copyright (c) 2009-2010 Tim Tiemens. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * * 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 Lesser General Public License for more details. * * * Contributors: * Tim Tiemens - initial API and implementation ******************************************************************************/ import java.math.BigInteger; import java.security.SecureRandom; import java.util.Random; public class Main { public static BigInteger createPrimeBigger(BigInteger valueThatDeterminesNumberOfBits) { Random random = new SecureRandom(); return createPrimeBigger(valueThatDeterminesNumberOfBits, random); } public static BigInteger createPrimeBigger(BigInteger valueThatDeterminesNumberOfBits, Random random) { int numbits = valueThatDeterminesNumberOfBits.bitLength() + 1; BigInteger ret = BigInteger.probablePrime(numbits, random); return ret; } }