float count = 10000;
int iMin = 1;
int iMax = (int) (count + 1);
int iP1 = (int)(count*0.45) + iMin;
int iP2 = (int)(count*0.25) + iP1;
int iP3 = (int)(count*0.15) + iP2;
int iP4 = (int)(count*0.1) + iP3;
int iP5 = (int)(count*0.05) + iP4;
int[] test = getRandomIntWithoutReduplicate(iMin, iMax, (int) count );
// Arrays.sort( test );
for( int a : test )
{
int iV = 1;
if (a >= iMin && a < iP1) {
iV = 1;
} else if (a >= iP1 && a < iP2) {
iV = 2;
} else if (a >= iP2 && a < iP3) {
iV = 3;
} else if (a >= iP3 && a < iP4) {
iV = 4;
} else if (a >= iP4 && a < iP5) {
iV = 5;
}
System.out.println( iV );
}
public static int[] getRandomIntWithoutReduplicate( int min, int max, int size )
{
int[] result = new int[size];
int arraySize = max - min;
int[] intArray = new int[arraySize];
// init intArray
for( int i = 0 ; i < intArray.length ; i++ )
{
intArray[i] = i + min;
}
// get randome interger without reduplicate
for( int i = 0 ; i < size ; i++ )
{
int c = getRandomInt( min, max - i );
int index = c - min;
swap( intArray, index, arraySize - 1 - i );
result[i] = intArray[ arraySize - 1 - i ];
}
return result;
}
private static void swap( int[] array, int x, int y )
{
int temp = array[x];
array[x] = array[y];
array[y] = temp;
}
/**
* get a random Integer with the range [min, max)
* @param min the minimum value
* @param max the maximum value
* @return the random Integer value
*/
public static int getRandomInt( int min, int max )
{
// include min, exclude max
int result = min + new Double( Math.random() * ( max - min ) ).intValue();
return result;
}