incubator-olio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r745184 [3/3] - in /incubator/olio/workload/php/trunk: ./ bin/ deploy/ src/org/ src/org/apache/ src/org/apache/olio/ src/org/apache/olio/workload/ src/org/apache/olio/workload/driver/ src/org/apache/olio/workload/fsloader/ src/org/apache/ol...
Date Tue, 17 Feb 2009 18:25:44 GMT
Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/RandomUtil.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/RandomUtil.java?rev=745184&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/RandomUtil.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/RandomUtil.java Tue
Feb 17 18:25:43 2009
@@ -0,0 +1,382 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.olio.workload.util;
+
+import com.sun.faban.driver.util.Random;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.logging.Logger;
+
+public class RandomUtil {
+
+    public static final String[] TIMEZONES = { "ACT", "AET", "AGT", "ART",
+        "AST", "Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa",
+        "Africa/Algiers", "Africa/Asmera", "Africa/Bamako", "Africa/Bangui",
+        "Africa/Banjul", "Africa/Bissau", "Africa/Blantyre",
+        "Africa/Brazzaville", "Africa/Bujumbura", "Africa/Cairo",
+        "Africa/Casablanca", "Africa/Ceuta", "Africa/Conakry", "Africa/Dakar",
+        "Africa/Dar_es_Salaam", "Africa/Djibouti", "Africa/Douala",
+        "Africa/El_Aaiun", "Africa/Freetown", "Africa/Gaborone",
+        "Africa/Harare", "Africa/Johannesburg", "Africa/Kampala",
+        "Africa/Khartoum", "Africa/Kigali", "Africa/Kinshasa", "Africa/Lagos",
+        "Africa/Libreville", "Africa/Lome", "Africa/Luanda",
+        "Africa/Lubumbashi", "Africa/Lusaka", "Africa/Malabo", "Africa/Maputo",
+        "Africa/Maseru", "Africa/Mbabane", "Africa/Mogadishu",
+        "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Niamey",
+        "Africa/Nouakchott", "Africa/Ouagadougou", "Africa/Porto-Novo",
+        "Africa/Sao_Tome", "Africa/Timbuktu", "Africa/Tripoli", "Africa/Tunis",
+        "Africa/Windhoek", "America/Adak", "America/Anchorage",
+        "America/Anguilla", "America/Antigua", "America/Araguaina",
+        "America/Argentina/Buenos_Aires", "America/Argentina/Catamarca",
+        "America/Argentina/ComodRivadavia", "America/Argentina/Cordoba",
+        "America/Argentina/Jujuy", "America/Argentina/La_Rioja",
+        "America/Argentina/Mendoza", "America/Argentina/Rio_Gallegos",
+        "America/Argentina/San_Juan", "America/Argentina/Tucuman",
+        "America/Argentina/Ushuaia", "America/Aruba", "America/Asuncion",
+        "America/Atikokan", "America/Atka", "America/Bahia", "America/Barbados",
+        "America/Belem", "America/Belize", "America/Blanc-Sablon",
+        "America/Boa_Vista", "America/Bogota", "America/Boise",
+        "America/Buenos_Aires", "America/Cambridge_Bay", "America/Campo_Grande",
+        "America/Cancun", "America/Caracas", "America/Catamarca",
+        "America/Cayenne", "America/Cayman", "America/Chicago",
+        "America/Chihuahua", "America/Coral_Harbour", "America/Cordoba",
+        "America/Costa_Rica", "America/Cuiaba", "America/Curacao",
+        "America/Danmarkshavn", "America/Dawson", "America/Dawson_Creek",
+        "America/Denver", "America/Detroit", "America/Dominica",
+        "America/Edmonton", "America/Eirunepe", "America/El_Salvador",
+        "America/Ensenada", "America/Fort_Wayne", "America/Fortaleza",
+        "America/Glace_Bay", "America/Godthab", "America/Goose_Bay",
+        "America/Grand_Turk", "America/Grenada", "America/Guadeloupe",
+        "America/Guatemala", "America/Guayaquil", "America/Guyana",
+        "America/Halifax", "America/Havana", "America/Hermosillo",
+        "America/Indiana/Indianapolis", "America/Indiana/Knox",
+        "America/Indiana/Marengo", "America/Indiana/Petersburg",
+        "America/Indiana/Vevay", "America/Indiana/Vincennes",
+        "America/Indianapolis", "America/Inuvik", "America/Iqaluit",
+        "America/Jamaica", "America/Jujuy", "America/Juneau",
+        "America/Kentucky/Louisville", "America/Kentucky/Monticello",
+        "America/Knox_IN", "America/La_Paz", "America/Lima",
+        "America/Los_Angeles", "America/Louisville", "America/Maceio",
+        "America/Managua", "America/Manaus", "America/Martinique",
+        "America/Mazatlan", "America/Mendoza", "America/Menominee",
+        "America/Merida", "America/Mexico_City", "America/Miquelon",
+        "America/Moncton", "America/Monterrey", "America/Montevideo",
+        "America/Montreal", "America/Montserrat", "America/Nassau",
+        "America/New_York", "America/Nipigon", "America/Nome",
+        "America/Noronha", "America/North_Dakota/Center",
+        "America/North_Dakota/New_Salem", "America/Panama",
+        "America/Pangnirtung", "America/Paramaribo", "America/Phoenix",
+        "America/Port-au-Prince", "America/Port_of_Spain", "America/Porto_Acre",
+        "America/Porto_Velho", "America/Puerto_Rico", "America/Rainy_River",
+        "America/Rankin_Inlet", "America/Recife", "America/Regina",
+        "America/Rio_Branco", "America/Rosario", "America/Santiago",
+        "America/Santo_Domingo", "America/Sao_Paulo", "America/Scoresbysund",
+        "America/Shiprock", "America/St_Johns", "America/St_Kitts",
+        "America/St_Lucia", "America/St_Thomas", "America/St_Vincent",
+        "America/Swift_Current", "America/Tegucigalpa", "America/Thule",
+        "America/Thunder_Bay", "America/Tijuana", "America/Toronto",
+        "America/Tortola", "America/Vancouver", "America/Virgin",
+        "America/Whitehorse", "America/Winnipeg", "America/Yakutat",
+        "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis",
+        "Antarctica/DumontDUrville", "Antarctica/Mawson", "Antarctica/McMurdo",
+        "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/South_Pole",
+        "Antarctica/Syowa", "Antarctica/Vostok", "Arctic/Longyearbyen",
+        "Asia/Aden", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau",
+        "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Ashkhabad", "Asia/Baghdad",
+        "Asia/Bahrain", "Asia/Baku", "Asia/Bangkok", "Asia/Beirut",
+        "Asia/Bishkek", "Asia/Brunei", "Asia/Calcutta", "Asia/Choibalsan",
+        "Asia/Chongqing", "Asia/Chungking", "Asia/Colombo", "Asia/Dacca",
+        "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai",
+        "Asia/Dushanbe", "Asia/Gaza", "Asia/Harbin", "Asia/Hong_Kong",
+        "Asia/Hovd", "Asia/Irkutsk", "Asia/Istanbul", "Asia/Jakarta",
+        "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka",
+        "Asia/Karachi", "Asia/Kashgar", "Asia/Katmandu", "Asia/Krasnoyarsk",
+        "Asia/Kuala_Lumpur", "Asia/Kuching", "Asia/Kuwait", "Asia/Macao",
+        "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila",
+        "Asia/Muscat", "Asia/Nicosia", "Asia/Novosibirsk", "Asia/Omsk",
+        "Asia/Oral", "Asia/Phnom_Penh", "Asia/Pontianak", "Asia/Pyongyang",
+        "Asia/Qatar", "Asia/Qyzylorda", "Asia/Rangoon", "Asia/Riyadh",
+        "Asia/Riyadh87", "Asia/Riyadh88", "Asia/Riyadh89", "Asia/Saigon",
+        "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai",
+        "Asia/Singapore", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi",
+        "Asia/Tehran", "Asia/Tel_Aviv", "Asia/Thimbu", "Asia/Thimphu",
+        "Asia/Tokyo", "Asia/Ujung_Pandang", "Asia/Ulaanbaatar",
+        "Asia/Ulan_Bator", "Asia/Urumqi", "Asia/Vientiane", "Asia/Vladivostok",
+        "Asia/Yakutsk", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores",
+        "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape_Verde",
+        "Atlantic/Faeroe", "Atlantic/Jan_Mayen", "Atlantic/Madeira",
+        "Atlantic/Reykjavik", "Atlantic/South_Georgia", "Atlantic/St_Helena",
+        "Atlantic/Stanley", "Australia/ACT", "Australia/Adelaide",
+        "Australia/Brisbane", "Australia/Broken_Hill", "Australia/Canberra",
+        "Australia/Currie", "Australia/Darwin", "Australia/Hobart",
+        "Australia/LHI", "Australia/Lindeman", "Australia/Lord_Howe",
+        "Australia/Melbourne", "Australia/NSW", "Australia/North",
+        "Australia/Perth", "Australia/Queensland", "Australia/South",
+        "Australia/Sydney", "Australia/Tasmania", "Australia/Victoria",
+        "Australia/West", "Australia/Yancowinna", "BET", "BST", "Brazil/Acre",
+        "Brazil/DeNoronha", "Brazil/East", "Brazil/West", "CAT", "CET", "CNT",
+        "CST", "CST6CDT", "CTT", "Canada/Atlantic", "Canada/Central",
+        "Canada/East-Saskatchewan", "Canada/Eastern", "Canada/Mountain",
+        "Canada/Newfoundland", "Canada/Pacific", "Canada/Saskatchewan",
+        "Canada/Yukon", "Chile/Continental", "Chile/EasterIsland", "Cuba",
+        "EAT", "ECT", "EET", "EST", "EST5EDT", "Egypt", "Eire", "Etc/GMT",
+        "Etc/GMT+0", "Etc/GMT+1", "Etc/GMT+10", "Etc/GMT+11", "Etc/GMT+12",
+        "Etc/GMT+2", "Etc/GMT+3", "Etc/GMT+4", "Etc/GMT+5", "Etc/GMT+6",
+        "Etc/GMT+7", "Etc/GMT+8", "Etc/GMT+9", "Etc/GMT-0", "Etc/GMT-1",
+        "Etc/GMT-10", "Etc/GMT-11", "Etc/GMT-12", "Etc/GMT-13", "Etc/GMT-14",
+        "Etc/GMT-2", "Etc/GMT-3", "Etc/GMT-4", "Etc/GMT-5", "Etc/GMT-6",
+        "Etc/GMT-7", "Etc/GMT-8", "Etc/GMT-9", "Etc/GMT0", "Etc/Greenwich",
+        "Etc/UCT", "Etc/UTC", "Etc/Universal", "Etc/Zulu", "Europe/Amsterdam",
+        "Europe/Andorra", "Europe/Athens", "Europe/Belfast", "Europe/Belgrade",
+        "Europe/Berlin", "Europe/Bratislava", "Europe/Brussels",
+        "Europe/Bucharest", "Europe/Budapest", "Europe/Chisinau",
+        "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar",
+        "Europe/Guernsey", "Europe/Helsinki", "Europe/Isle_of_Man",
+        "Europe/Istanbul", "Europe/Jersey", "Europe/Kaliningrad", "Europe/Kiev",
+        "Europe/Lisbon", "Europe/Ljubljana", "Europe/London",
+        "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta",
+        "Europe/Mariehamn", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow",
+        "Europe/Nicosia", "Europe/Oslo", "Europe/Paris", "Europe/Prague",
+        "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/San_Marino",
+        "Europe/Sarajevo", "Europe/Simferopol", "Europe/Skopje", "Europe/Sofia",
+        "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane",
+        "Europe/Tiraspol", "Europe/Uzhgorod", "Europe/Vaduz", "Europe/Vatican",
+        "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw",
+        "Europe/Zagreb", "Europe/Zaporozhye", "Europe/Zurich", "GB", "GB-Eire",
+        "GMT", "GMT0", "Greenwich", "HST", "Hongkong", "IET", "IST", "Iceland",
+        "Indian/Antananarivo", "Indian/Chagos", "Indian/Christmas",
+        "Indian/Cocos", "Indian/Comoro", "Indian/Kerguelen", "Indian/Mahe",
+        "Indian/Maldives", "Indian/Mauritius", "Indian/Mayotte",
+        "Indian/Reunion", "Iran", "Israel", "JST", "Jamaica", "Japan",
+        "Kwajalein", "Libya", "MET", "MIT", "MST", "MST7MDT",
+        "Mexico/BajaNorte", "Mexico/BajaSur", "Mexico/General",
+        "Mideast/Riyadh87", "Mideast/Riyadh88", "Mideast/Riyadh89", "NET",
+        "NST", "NZ", "NZ-CHAT", "Navajo", "PLT", "PNT", "PRC", "PRT", "PST",
+        "PST8PDT", "Pacific/Apia", "Pacific/Auckland", "Pacific/Chatham",
+        "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury",
+        "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti",
+        "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal",
+        "Pacific/Guam", "Pacific/Honolulu", "Pacific/Johnston",
+        "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein",
+        "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Midway",
+        "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea",
+        "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Pitcairn",
+        "Pacific/Ponape", "Pacific/Port_Moresby", "Pacific/Rarotonga",
+        "Pacific/Saipan", "Pacific/Samoa", "Pacific/Tahiti", "Pacific/Tarawa",
+        "Pacific/Tongatapu", "Pacific/Truk", "Pacific/Wake", "Pacific/Wallis",
+        "Pacific/Yap", "Poland", "Portugal", "ROK", "SST", "Singapore",
+        "SystemV/AST4", "SystemV/AST4ADT", "SystemV/CST6", "SystemV/CST6CDT",
+        "SystemV/EST5", "SystemV/EST5EDT", "SystemV/HST10", "SystemV/MST7",
+        "SystemV/MST7MDT", "SystemV/PST8", "SystemV/PST8PDT", "SystemV/YST9",
+        "SystemV/YST9YDT", "Turkey", "UCT", "US/Alaska", "US/Aleutian",
+        "US/Arizona", "US/Central", "US/East-Indiana", "US/Eastern",
+        "US/Hawaii", "US/Indiana-Starke", "US/Michigan", "US/Mountain",
+        "US/Pacific", "US/Pacific-New", "US/Samoa", "UTC", "Universal", "VST",
+        "W-SU", "WET", "Zulu"};
+
+
+    // Phone comes as +1 888 999 0000 or +77 66 999 0000 for non-US.
+    // 50% of the time, do US, 50% non-us.
+    public static String randomPhone(Random r, StringBuilder b) {
+        String v = r.makeNString(1, 2);
+        if (v.length() == 1) {
+            b.append("+1 ");
+            v = r.makeNString(3, 3);
+            b.append(v).append(' ');
+        } else {
+            b.append("+").append(v);
+            v = r.makeNString(2, 2);
+            b.append(' ').append(v).append(' ');
+        }
+        v = r.makeNString(3, 3);
+        b.append(v).append(' ');
+        v = r.makeNString(4, 4);
+        b.append(v);
+        return b.toString();
+    }
+
+    public static String randomTimeZone(Random r) {
+        return TIMEZONES[r.random(0, TIMEZONES.length - 1)];
+    }
+
+    public static StringBuilder randomName(Random r, StringBuilder b,
+                                           int minLength, int maxLength) {
+        if (minLength < 1 || maxLength < minLength)
+            throw new IllegalArgumentException();
+        b.append(r.makeCString(1, 1).toUpperCase());
+        b.append(r.makeCString(minLength - 1, maxLength - 1).toLowerCase());
+        return b;
+    }
+
+    /**
+     * From http://tagsonomy.com/index.php/dynamic-growth-of-tag-clouds/
+
+     * "It took only 10 users (not quite 1.5% of the current total) before
+     * the top 3 tags were tagging ontology folksonomy, conveying much
+     * the same sense, with only the use of tagging instead of tags
+     * making this different from the current set of 3."<br>
+     *
+     * In order to achieve a high concentration on the first tags added
+     * to the system, we use a negative exponential distribution to select
+     * the tags.
+     *
+     * @param r The random value generator
+     * @param meanRatio The point of mean in the range from 0 to 1
+     * @return The randomly selected tag id starting with 1, with a
+     *         high probability of the first tags being selected.
+     */
+    public static int randomTagId(Random r, double meanRatio) {
+        Logger logger = Logger.getLogger(RandomUtil.class.getName());
+        double mean = ScaleFactors.tagCount * meanRatio;
+
+        int selected;
+        int loops = 0;
+
+        do {
+            double x = r.drandom(0.0, 1.0);
+            if (x == 0)
+                x = 0.05;
+
+            // We use a negative exponential distribution to select the tags.
+            // The first tags tend to be the most often used.
+            selected = (int)(mean * -Math.log(x));
+
+            // if (selected >= ScaleFactors.tagCount)
+            //    logger.warning("Selected: " + selected);
+
+            // However, if we exceed the limit, we do not select the last one.
+            // We redo the selection instead.
+        } while (selected >= ScaleFactors.tagCount && loops++ < 10);
+
+        if (loops >= 10)
+            logger.severe("Exceeded loop limit. Selected:" +
+                            selected + " TagCount: " + ScaleFactors.tagCount);
+
+        // We use the user name mechanism to create the tag names
+        return ++selected;
+    }
+       
+    /**
+     * Returns a random tag name. Implicitly calls randomTagId.
+     * @param r The random value generator
+     * @return The randomly selected tag name.
+     */
+    public static String randomTagName(Random r) {
+        return UserName.getUserName(r.random(1, ScaleFactors.tagCount));
+        //return UserName.getUserName(randomTagId(r, 0.1));
+    }
+
+    /**
+     * Randomly creates text between length x and y, inclusive that is
+     * separated by spaces. The words are between 1 and 12 characters long.
+     */
+    public static String randomText(Random r, int x, int y) {
+        int length = r.random(x, y);
+        StringBuilder buffer = new StringBuilder(length);
+        int leftover = length;
+        while (leftover > 0) {
+            String word = r.makeCString(1, leftover < 12 ? leftover : 12);
+            buffer.append(word).append(' ');
+            leftover -= word.length() + 1;
+        }
+        return buffer.toString();
+    }
+
+    public static String randomEventFromJson (Random r, StringBuilder jsonStr, String objectKey,
String attribute) {
+        try {
+            JSONObject job = new JSONObject(jsonStr.toString());
+
+            JSONArray ja = job.getJSONArray(objectKey);
+
+            List<String> list = new ArrayList<String>();
+
+            for (int i = 0; i < ja.length(); i++) {
+                if (!ja.isNull(i)) {
+                    JSONObject obj = ja.getJSONObject(i);
+                    String value = obj.getString(attribute);
+                    list.add(value);
+                }
+            }
+            if (list.size() == 0)
+                return null;
+            
+            int rint = r.random(0, list.size()-1);
+            return list.get(rint);
+            
+        } catch (JSONException ex) {
+            Logger logger = Logger.getLogger(RandomUtil.class.getName());
+            logger.severe("Could not create JSON Object - str = " + jsonStr.toString());
+        }
+        return null;
+    }
+    /**
+     * Randomly selects an event from the events page.
+     * @param r The random value generator
+     * @param eventListPage The page from the response buffer
+     * @return The selected event id, as a string
+     */
+    public static String randomEvent(Random r, StringBuilder eventListPage) {
+        String search1 = "<a href=\"events.";
+        String search2 = "?socialEventID=";
+        int idx = 0;
+        HashSet<String> eventIdSet = new HashSet<String>();
+        for (;;) {
+            idx = eventListPage.indexOf(search1, idx);
+            if (idx == -1)
+                break;
+            // We skip this the php or jsp, just knowing it is 3 chars
+            idx += search1.length() + 3;
+            // Check matching search2
+            if (eventListPage.indexOf(search2, idx) == idx) {
+                idx += search2.length();
+                int endIdx = eventListPage.indexOf("\"", idx);
+                if (endIdx == -1)
+                    break;                
+                eventIdSet.add(eventListPage.substring(idx, endIdx).trim());
+                idx = endIdx;
+            }
+        }
+        int size = eventIdSet.size();
+        if (size == 0)
+            return null;
+
+        String[] eventIds = new String[size];
+        eventIds = eventIdSet.toArray(eventIds);
+        return eventIds[r.random(0, size - 1)];
+    }
+
+    // Main for testing RandomEvent.
+    public static void main(String[] args) throws Exception {
+        FileReader reader = new FileReader(args[0]);
+        StringBuilder page = new StringBuilder();
+        char[] readBuffer = new char[8192];
+        int readSize;
+        while ((readSize = reader.read(readBuffer, 0, readBuffer.length))
+                != -1)
+            page.append(readBuffer, 0, readSize);
+        Random r = new Random();
+        String selected = randomEvent(r, page);
+        System.out.println("Selected: " + selected);
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/ScaleFactors.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/ScaleFactors.java?rev=745184&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/ScaleFactors.java
(added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/ScaleFactors.java
Tue Feb 17 18:25:43 2009
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: ScaleFactors.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.util;
+
+import java.util.logging.Logger;
+
+/**
+ * This static class all the scale factors used for loading the data and
+ * load generation.
+ */
+public class ScaleFactors {
+
+    /** The ratio between loaded and active users. */
+    public static final int USERS_RATIO = 100;
+    public static int activeUsers = -1;
+
+    /** The total number of loaded users */
+    public static int users;
+    public static int events;
+    public static int tagCount;
+
+    private static Logger logger =
+                        Logger.getLogger(ScaleFactors.class.getName());
+
+    /**
+     * Sets the number of users for the run/load.
+     * @param userCount
+     */
+    public static void setActiveUsers(int userCount) {
+        if (userCount < 25) {
+            logger.warning("Trying to load for " + userCount + " concurrent " +
+                    "users which is below the minimum of 25 users. " +
+                    "Adjusting to 25 users");
+            userCount = 25;
+        }
+        if (activeUsers == -1) {
+            activeUsers = userCount;
+            users = activeUsers * USERS_RATIO;
+            tagCount = getTagCount(users);
+            events = tagCount * 3;
+        }
+    }
+
+    /**
+     * From http://tagsonomy.com/index.php/dynamic-growth-of-tag-clouds/
+     * "As of this writing, a little over 700 users have tagged it, with 450+
+     * with 450+ unique tags, roughly two-thirds of which tags were (of course)
+     * used by one and only one user."<br>
+     *
+     * This function uses a cumulative half logistic distribution to determine
+     * the tag growth. We have tested the distribution to be close to the
+     * quote above. I.e. 175 multi-user tags for 700 users. The quote above
+     * gives us one-third of 450 which is 150. Close enough.
+     *
+     * @param users The users of the data loaded.
+     * @return The tag count at this users
+     */
+    public static int getTagCount(int users) {
+        double prob = cumuHalfLogistic(users, 10000);
+        // We limit to 5000 tags
+        return (int) Math.round(5000 * prob);
+    }
+
+    /**
+     * The cumulative half logistic distribution itself, in the flesh!
+     * @param x The value on the x axis, in this case the number of users
+     * @param scale Determines the x-stretch of the curve how far it takes
+     *        for the probability to converge to 1
+     * @return The resulting probability or y axis
+     */
+    private static double cumuHalfLogistic(double x, double scale) {
+        double power = -x / scale;
+        return (1d - Math.exp(power)) / (1d + Math.exp(power));
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/Scramble.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/Scramble.java?rev=745184&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/Scramble.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/Scramble.java Tue
Feb 17 18:25:43 2009
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * v
+ * $Id: Scramble.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.util;
+
+
+import java.util.*;
+
+/**
+ * Scramble scrambles char sequences in a controlled random fasion. The
+ * outcome of running the Scramble utility will be the same for the same
+ * random number generator. Scramble is a utility to generate a code segment
+ * and is not used in the benchmark itself.
+ *
+ * @author Akara Sucharitakul
+ */
+public class Scramble {
+
+    /**
+     * The alpha-numeric char sequence.
+     */
+    private static char[] alpha =
+        {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
+         'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
+         's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_'};
+	    /**
+     * The alpha characters only. A name would start with these.
+     */
+    private static char[] characs =
+        {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+         'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
+ 
+    /**
+     * Generates the char sequences for each length.
+     *
+     * @param digits The length of the name to generate the scramble for
+     * @return The scrambled sequence for each digit
+     */
+    public static char[][] genChars(int digits) {
+        Random r = new Random(digits);
+        char[][] result = new char[digits][];
+        ArrayList<Character> list = new ArrayList<Character>(alpha.length);
+
+        // Generate scrambled sequence for first digit.
+        result[0] = new char[characs.length];
+        for (int j = 0; j < characs.length; j++)
+            list.add(characs[j]);
+        for (int j = 0; j < characs.length; j++) {
+            int idx = r.nextInt(list.size());
+            result[0][j] = list.remove(idx);
+        }
+
+        // Generate scrambled sequence for the following digits.
+        for (int i = 1; i < digits; i++) {
+            result[i] = new char[alpha.length];
+            for (int j = 0; j < alpha.length; j++)
+                list.add(alpha[j]);
+            for (int j = 0; j < alpha.length; j++) {
+                int idx = r.nextInt(list.size());
+                result[i][j] = list.remove(idx);
+            }
+        }
+        return result;
+    } 
+
+    /**
+     * Dumps the generated scramble to standard output in a ready-to-use
+     * Java array representation. The user will have to redirect the output
+     * to a Java class by him/herself.
+     *
+     * @param arrays The scramble for each length
+     */
+    public static void dumpArrays(char[][][] arrays) {
+        StringBuilder buffer = new StringBuilder(8096);
+        buffer.append("private static final char[][][] scramble = {");
+        for (int i = 0; i < arrays.length; i++) {
+            buffer.append('{');
+            for (int j = 0; j < arrays[i].length; j++) {
+                buffer.append('{');
+                for (int k = 0; k < arrays[i][j].length; k++) {
+                    buffer.append("'");
+                    buffer.append(arrays[i][j][k]);
+                    if (k < arrays[i][j].length - 1) {
+                        buffer.append("',");
+                        if (buffer.length() > 70) {
+                            System.out.println(buffer);
+                            buffer.setLength(0);
+                        } else {
+                            buffer.append(' ');
+                        }
+                    } else {
+                        buffer.append("'");
+                    }
+                }
+                buffer.append("}");
+                if (j < arrays[i].length - 1) {
+                    buffer.append(',');
+                    System.out.println(buffer);
+                    buffer.setLength(0);
+                }
+            }
+            buffer.append("}");
+            if (i < arrays.length - 1) {
+                buffer.append(',');
+                System.out.println(buffer);
+                buffer.setLength(0);
+            }
+        }
+        buffer.append("};");
+        System.out.println(buffer);
+    }
+
+    /**
+     * The main method to drive the scrambling.
+     *
+     * @param args ignored
+     */
+    public static void main(String[] args) {
+        char[][][] results = new char[8][][];
+        char[][] nullArray = new char[1][1];
+        nullArray[0][0] = '0';
+        for (int i = 0; i < 2; i++)
+            results[i] = nullArray;
+        for (int i = 2; i < 8; i++)
+            results[i] = genChars(i + 1);
+        dumpArrays(results);
+    }
+}

Added: incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/UserName.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/UserName.java?rev=745184&view=auto
==============================================================================
--- incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/UserName.java (added)
+++ incubator/olio/workload/php/trunk/src/org/apache/olio/workload/util/UserName.java Tue
Feb 17 18:25:43 2009
@@ -0,0 +1,260 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * 
+ * $Id: UserName.java,v 1.1.1.1 2008/09/29 22:33:08 sp208304 Exp $
+ */
+package org.apache.olio.workload.util;
+
+import java.util.HashSet;
+import java.io.*;
+
+/**
+ * The user utility creates usernames and passwords from user ids.
+ * It uses the scrambled character sequences generated by the Scramble
+ * class. The username length distribution are controlled so 5% of the
+ * users have 3 letter names, 8% of the users have 4 letter names,
+ * 17% of the users have 5 letter names, 25% of the users have 6 letter
+ * names, 24% of the users have 7 letter names, and 21% of the users
+ * have 8 letter names. This ratio is based on Sun's own users that
+ * DO NOT use standard names such as ab123456.<p>
+ * At the current state, this utility can generate 711,880 non-duplicate
+ * names.
+ *
+ * @author Akara Sucharitakul
+ */
+public class UserName {
+
+    private static final char[][][] scramble = {{{'0'}}, {{'0'}},
+    {{'s', 'k', 'u', 'p', 'n', 't', 'j', 'z', 'b', 'g', 'q', 'l', 'w', 'd',
+    'v', 'y', 'm', 'f', 'x', 'i', 'c', 'h', 'r', 'o', 'e', 'a'},
+    {'w', '_', 'q', 'l', 'z', 'h', 'j', 'k', '1', '6', 'e', '5', '4', 't', 'b',
+    '2', 'p', 'r', 'g', 'm', '8', '3', 'c', 'u', '7', 'v', 'i', 'y', 'o', 'a',
+    'x', 'n', '0', '9', 's', 'd', 'f'},
+    {'8', '7', '2', 'm', 'l', 's', 'q', '6', '1', 'j', 'b', 'n', '3', 'i', '_',
+    'w', 'a', 'z', '4', 'x', 'e', 'f', '9', 'c', 'g', 't', 'h', '0', 'd', 'y',
+    'k', 'v', 'u', 'p', 'r', '5', 'o'}},
+    {{'q', 'c', 'r', 'p', 'm', 'o', 'n', 'y', 't', 'x', 'a', 'k', 'l', 's',
+    'e', 'g', 'z', 'h', 'w', 'j', 'v', 'u', 'b', 'f', 'i', 'd'},
+    {'0', 'g', 'l', '8', 'f', 'p', 'x', 'q', 'm', '6', 's', 'y', 'c', '2', '7',
+    'e', '4', '5', 'v', 'b', 'z', 'i', 'd', 'h', '1', 'n', '3', '9', 'w', 'o',
+    '_', 'r', 'j', 't', 'k', 'u', 'a'},
+    {'5', 'e', '0', '4', 'j', 'd', 'a', 'b', 'g', 'w', 'n', 'v', '3', 'u', '9',
+    'x', 'i', 'c', 'h', 'q', 'y', 'r', '_', 'm', 't', '6', '8', '2', 'l', 'k',
+    'p', '7', 's', 'o', 'z', 'f', '1'},
+    {'r', 'v', 'g', 'a', '0', 'w', 't', '7', '5', '_', 'o', '6', 'f', 'z', 'j',
+    '2', 'c', 'e', '4', '1', 's', 'y', 'p', '8', 'n', 'u', '3', 'l', 'k', 'h',
+    'd', 'b', 'q', 'x', 'i', '9', 'm'}},
+    {{'p', 's', 'c', 'o', 'r', 't', 'u', 'i', 'k', 'q', 'v', 'e', 'f', 'x',
+    'n', 'j', 'y', 'w', 'z', 'd', 'a', 'b', 'g', 'm', 'l', 'h'},
+    {'i', 'f', 'w', '0', '5', 'p', '7', 'o', '6', 'z', '8', 'h', 't', '2', '4',
+    'u', 'a', 'x', 'r', 's', '9', 'v', 'k', 'j', 'e', 'g', '3', 'q', 'm', '1',
+    'l', 'y', 'd', 'n', '_', 'c', 'b'},
+    {'n', 'z', 'q', 'd', '8', '1', '5', 'o', 'b', 'u', 'e', 'a', 'c', '2', 'y',
+    'w', 'k', '9', 'i', '7', 'h', '_', '3', '0', 'j', 'g', 'l', 'm', 'p', 's',
+    'v', 't', '4', 'x', '6', 'f', 'r'},
+    {'f', 'd', '5', 't', 'j', 'e', 'h', 'q', 'u', 'c', 'b', 'w', 'l', 'k', 'a',
+    'n', 'r', 'm', '1', 'o', '_', 'y', '6', 's', '7', 'g', 'i', '2', '0', 'p',
+    'x', 'v', '3', '4', 'z', '9', '8'},
+    {'4', 'm', 'q', 'o', '9', 'v', 'z', 'w', '7', '6', '5', '8', 'f', 'g', 'd',
+    'a', 'p', 'j', '1', '_', 'y', '3', 'h', 'r', 't', 'c', 'n', 'l', '0', 'e',
+    'k', 'b', 'x', 'i', '2', 's', 'u'}},
+    {{'r', 'b', 'd', 'm', 'f', 't', 'x', 'e', 'i', 'o', 's', 'p', 'a', 'l',
+    'g', 'h', 'n', 'w', 'z', 'q', 'u', 'v', 'k', 'j', 'c', 'y'},
+    {'h', 'i', 'b', 'f', '2', 'o', 'd', 'u', '7', '9', 'w', 'v', 'j', '3', '6',
+    'g', 'z', 'p', 'n', '8', 'y', 'k', 'x', 'q', '5', 's', 't', 'a', '1', '4',
+    '0', 'e', 'c', 'm', 'r', 'l', '_'},
+    {'y', '3', 'w', 'h', 'v', 'u', 'e', 'q', 'm', 'z', '9', 'x', 'k', '7', 'p',
+    'r', 't', 'n', '4', 'f', 'o', '2', '5', 'i', 'l', 'a', '6', '8', 'g', '1',
+    '_', 'b', 'd', '0', 's', 'j', 'c'},
+    {'6', 'c', 'f', '3', '2', 'v', 'm', 'l', 'x', 'k', 'e', '_', '7', 'a', 's',
+    '0', 'j', 'n', 'd', 'z', 'u', '4', 't', 'o', 'g', '5', 'w', 'h', 'p', 'b',
+    'i', '1', 'q', '8', 'r', 'y', '9'},
+    {'i', 'e', 'p', 'g', 'h', 'b', '1', 'a', 'x', 'm', 'o', '7', 'l', 'u', 'z',
+    'w', '0', '8', '9', 'd', 'f', '2', '_', '5', 'c', 'n', 'r', '6', 'j', 'v',
+    'q', 't', 's', '4', 'k', '3', 'y'},
+    {'t', 'n', 'v', 'g', 's', 'j', 'p', 'l', 'b', '8', 'd', '_', 'q', 'u', 'z',
+    '2', '5', '7', 'x', 'i', 'o', 'r', '9', '0', 'f', 'w', 'k', '6', '4', '3',
+    'e', 'c', 'a', 'h', 'm', '1', 'y'}},
+    {{'q', 'o', 'x', 'j', 'g', 'r', 'k', 'p', 'a', 'e', 'i', 'w', 'u', 'n',
+    's', 'f', 'c', 'b', 'z', 'y', 't', 'v', 'm', 'h', 'l', 'd'},
+    {'z', 'g', 'm', '7', 'r', 'l', 'o', 'q', 't', '0', '9', 'b', 'w', '3', '2',
+    'y', '1', 'e', 'p', 's', '6', 'x', '5', 'v', 'i', 'n', '_', '4', 'a', 'k',
+    'u', 'f', 'c', 'd', 'h', 'j', '8'},
+    {'1', '9', 'c', 't', 'p', 'm', 'e', '5', 'f', 'y', 'r', 'g', 'w', 'j', 'i',
+    'x', '3', 'u', '8', '6', 'd', 'k', 's', '4', 'b', 'l', 'h', 'q', 'n', '7',
+    '2', 'z', 'a', 'o', '0', 'v', '_'},
+    {'g', 'v', 'r', 'l', 'h', 'a', '4', '0', 'k', '_', '2', 'j', 'b', 't', 'p',
+    'i', 'z', '5', '7', 'm', '3', '1', 'w', 'e', '6', 'u', 'f', 'y', '9', 'n',
+    'x', 'o', 'c', 'd', 's', 'q', '8'},
+    {'q', 'u', '0', '4', 'f', 'j', 'r', 'w', '8', '9', 't', 'k', 'h', '2', 'i',
+    'b', 'n', 'g', 'z', 'x', '3', 'd', 'e', 'a', 's', '6', '1', '5', 'v', 'o',
+    '_', 'l', 'm', 'y', 'c', 'p', '7'},
+    {'b', '7', 'x', 'r', 'a', '8', 'z', 'm', 'q', 'i', 't', 'v', 'c', 'd', '6',
+    'j', 'k', 'y', '0', '9', 'f', '3', '2', 'h', 's', 'w', 'l', '1', 'u', '_',
+    'g', 'o', 'e', 'n', 'p', '5', '4'},
+    {'v', 'j', '1', 'n', '8', 's', '_', 'q', 'u', 'e', '3', 'c', 'o', '9', 'm',
+    'h', 't', '0', 'f', '4', 'd', 'r', '5', 'x', '2', '6', 'w', 'a', 'i', 'z',
+    '7', 'b', 'l', 'k', 'g', 'y', 'p'}},
+    {{'o', 'g', 'l', 'k', 'e', 'q', 'r', 'p', 't', 'w', 'u', 'h', 'j', 'a',
+    'i', 'v', 'd', 'y', 'z', 'b', 'c', 'm', 'x', 'n', 'f', 's'},
+    {'3', 'y', 'f', 't', '6', 'q', 'z', 'r', 'b', '1', 'j', '0', '7', '2', '_',
+    'a', 'g', '9', '4', 'l', 'v', 'd', 'c', 'm', 'o', 'i', 'k', '8', '5', 'x',
+    'w', 'n', 'h', 'u', 'p', 'e', 's'},
+    {'d', 'v', 'l', 'b', 'j', '5', 'y', '8', 'o', 'p', '0', 'q', 'x', 'u', 's',
+    'w', '7', '3', 'h', 't', '_', 'n', '2', 'c', 'm', 'r', '6', 'g', 'k', 'z',
+    'e', '1', 'f', '9', '4', 'i', 'a'},
+    {'a', 'f', 'y', 'o', 'w', 'z', 'b', 'i', 'd', '7', '_', 'm', 's', 'p', '1',
+    '4', 'x', 'l', 'r', '9', 'j', 'q', 'k', 'v', '6', 'g', '3', 't', 'h', 'e',
+    '2', '0', 'n', '5', '8', 'u', 'c'},
+    {'r', 'c', 'q', 'x', '1', 'a', 'u', '7', 'k', '8', 'p', '0', '9', 'f', 'j',
+    'n', 'b', '3', 'z', 'o', '_', 'd', 'v', '4', 'g', 'i', 's', 'e', 'w', 'y',
+    '2', 'm', 't', '5', 'h', '6', 'l'},
+    {'s', '_', '2', 'v', 'z', 'f', '1', '7', 'k', 'o', 'd', '6', '8', 'j', 'i',
+    'q', '0', 'x', 'a', 'm', 'r', 't', 'w', 'h', 'y', 'n', 'l', 'u', 'c', 'p',
+    'g', '4', '9', '3', '5', 'e', 'b'},
+    {'u', '5', 'h', 'x', 'y', 'a', '4', '8', 'z', 'i', 'g', 's', '2', 'n', 'p',
+    'b', 'q', 'o', '6', '1', '0', 'w', 'e', '3', '_', 'j', 'v', '9', 'k', 'm',
+    'd', 'r', 't', '7', 'f', 'l', 'c'},
+    {'t', 'z', 'n', 'y', '6', 'm', 'i', 'w', 'c', '2', 'f', 'q', 'e', 'h', '_',
+    'v', 'j', '9', '0', '8', 's', '5', 'g', 'd', 'p', 'l', '4', 'u', 'o', '1',
+    'k', '3', 'r', 'b', 'a', 'x', '7'}}};
+
+
+    // Note that these sum up to 100
+    private static final int[] length_percent = { 0, 0, 5, 8, 17, 25, 24, 21 };
+
+    private static int[] selector = new int[length_percent.length];
+
+    static {
+        selector[0] = length_percent[0];
+        for (int i = 1; i < selector.length; i++)
+            selector[i] = selector[i - 1] + length_percent[i];
+    }
+
+    /**
+     * Obtains the unique user name for the given user id.
+     * @param id The user id
+     * @return The unique user name
+     */
+    public static String getUserName(long id) {
+
+        // Since id starts with 1, we have to shift it to start with 0 for
+        // our operations.
+        --id;
+
+        // We divide the ids into sets, each set has 100 users.
+        int setId = (int) (id / 100);
+
+        // Then we obtain the per-set id 0..99
+        int psid = (int) (id % 100);
+
+        // Here we reverse odd ids to ovid cluttering of shorter names
+        // in the lower range and longer ones in the upper range of each
+        // 100.
+        if (psid % 2 == 1)
+            psid = 100 - psid;
+
+        // For selection, we do not want to make the same name lengths
+        // contigous. So we switch the digits on psid.
+        psid = (psid % 10) * 10 + (psid / 10);
+
+
+        // This outcoming psid is used for digit selection.
+
+        // Next, choose the length.
+        int lengthSequence = 0; // This is the sequence number for the psid
+                                // having this length within these 100 names.
+        int len; // For now, pretend 0 is OK, but we'll shift is back to 1.
+        for (len = 0; len < selector.length; len++) {
+            if (psid < selector[len]) {
+                if (len == 0)
+                    lengthSequence = psid;
+                else
+                    lengthSequence = psid - selector[len - 1];
+                break;
+            }
+        }
+        // Here we shift it back so len is from 1 to whatever.
+        ++len;
+
+        // Now as we know the id, psid, and the name length to use,
+        // we have to generate the name.
+        char[] name = new char[len];
+        int[] offset = new int[len];
+
+        // The lengthId is the unique identifier for this length and is the
+        // value we use to get the name.
+        int lengthId = length_percent[len - 1] * setId + lengthSequence;
+
+        // Now we calculate the initial offset into the scrambled chars
+        // using last digit first.
+        for (int i = 0; i < len; i++) {
+            offset[i] = lengthId % scramble[len - 1][i].length;
+            lengthId /= scramble[len - 1][i].length;
+        }
+
+        // The first offset is now taken as is.
+        name[0] = scramble[len - 1][0][offset[0]];
+
+        for (int i = 1; i < len; i++) {
+            // We adjust the offset once again to avoid same name lenghts
+            // to have many of the same characters. We use the previous
+            // offset to step up the current offset.
+            offset[i] = (offset[i] + offset[i - 1]) %
+                    scramble[len - 1][i].length;
+            // And finally we assign the rest of the name.
+            name[i] = scramble[len - 1][i][offset[i]];
+        }
+
+        return new String(name);
+    }
+
+    /**
+     * The main method is used for testing user name generation.
+     * It prints out all the user names generated and the
+     * percentages of user names for each length. It also
+     * reports duplicate users, whenever found.
+     */
+    public static void main (String[] args) throws Exception {
+        long limit = Long.parseLong(args[0]) * 100;
+	FileWriter tmpfile;
+	if (args.length <= 1)
+		tmpfile = new FileWriter("/tmp/users.txt");
+	else    tmpfile = new FileWriter(args[1]);
+		
+        int[] nameLength = new int[8];
+        HashSet<String> set = new HashSet<String>((int) (limit - 1));
+
+        for (long i = 1; i <= limit; i++) {
+            String name = getUserName(i);
+            System.out.println("User " + i + ": " + name);
+            tmpfile.write(name + "\n");
+            ++nameLength[name.length() - 1];
+            if (!set.add(name))
+                System.out.println("Alert! Duplicate name: " + name);
+        }
+	tmpfile.close();
+        long count = 0;
+        for (int i = 0; i < nameLength.length; i++) {
+            count += nameLength[i];
+        }
+        for (int i = 0; i < nameLength.length; i++) {
+            System.out.println("Length " + (i + 1) + ", count " +
+                    nameLength[i] + ", " + (100d * nameLength[i]/count) + "%");
+        }
+    }
+}



Mime
View raw message