Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Random; public class Main { public static String getNumberRadim(int n) { if (n < 1 || n > 10) { throw new IllegalArgumentException("cannot random " + n + " bit number"); } Random ran = new Random(); if (n == 1) { return String.valueOf(ran.nextInt(10)); } int bitField = 0; char[] chs = new char[n]; for (int i = 0; i < n; i++) { while (true) { int k = ran.nextInt(10); if ((bitField & (1 << k)) == 0) { bitField |= 1 << k; chs[i] = (char) (k + '0'); break; } } } return new String(chs); } }