Here you can find the source of splitBigInt(BigInteger value, int n)
public static BigInteger[] splitBigInt(BigInteger value, int n)
//package com.java2s; //License from project: Open Source License import java.math.BigInteger; public class Main { public static BigInteger[] splitBigInt(BigInteger value, int n) { if (n <= 1) { return new BigInteger[] { value }; }//from w w w . j a v a2s .c o m BigInteger[] values = new BigInteger[n]; BigInteger total = BigInteger.ZERO; for (int i = 0; i < n; ++i) { values[i] = value.multiply(BigInteger.valueOf(Math.round(Math.random() * 100))); total = total.add(values[i]); } BigInteger mod = total.divide(value); if (mod.compareTo(BigInteger.ZERO) == 0) { return new BigInteger[] { value }; } total = BigInteger.ZERO; for (int i = 0; i < n; ++i) { values[i] = values[i].divide(mod); total = total.add(values[i]); } int randIndex = (int) Math.ceil(Math.random() * values.length) - 1; //Add any remainder to a random index values[randIndex] = values[randIndex].add(value.subtract(total)); return values; } }