Random Example in Java Using with HashMap
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Random;
public class RandomGeneratorExample{
static Random myRandomGenerator = new Random();
public static void main(String[] args)
{
HashMap<Integer,Integer> myHashMap = new HashMap<Integer,Integer>();
for(int i=0;i<1000;i++)
{
int generatedNumber = (myRandomGenerator.nextInt(10))+1;
if(myHashMap.containsKey(generatedNumber))
{
int k = myHashMap.get(generatedNumber);
k++;
myHashMap.put(generatedNumber, k);
}
else
myHashMap.put(generatedNumber,1 );
}
System.out.println(myHashMap);
}
}