testRandomTokenIP.java Source code

Java tutorial

Introduction

Here is the source code for testRandomTokenIP.java

Source

import business.cache.BlackListCache;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.RandomStringUtils;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author dathn
 */
public class testRandomTokenIP {
    public static final int size = 1000000;
    public static Map<String, Boolean> list = new HashMap<String, Boolean>(size);

    public static void main(String[] args) {

        int count = 0;
        for (int i = 0; i < size; i++) {
            String ip = RandomStringUtils.random(4, true, true);
            while (list.containsKey(ip)) {
                ip = RandomStringUtils.random(4, true, true);
            }
            if (list.containsKey(ip)) {
                count++;
                System.out.println("Da trung:" + count);
            }
            list.put(ip, Boolean.TRUE);

        }

    }

}