View RSS Feed

fatabass

Checking for Randomness of Java with HashMap

Rating: 1 votes, 1.00 average.
by , 02-07-2012 at 11:19 PM (1051 Views)
Java Code:
package myPaackkage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;
import java.util.Random;

public class SayisalGenerator {
	
	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);
	}
}

Submit "Checking for Randomness of Java with HashMap" to Facebook Submit "Checking for Randomness of Java with HashMap" to Digg Submit "Checking for Randomness of Java with HashMap" to del.icio.us Submit "Checking for Randomness of Java with HashMap" to StumbleUpon Submit "Checking for Randomness of Java with HashMap" to Google

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments