TestUtil.java :  » Utilities » androidpwsafe » org » pwsafe » android » Android Open Source

Android Open Source » Utilities » androidpwsafe 
androidpwsafe » org » pwsafe » android » TestUtil.java
/*
 * Copyright (c) 2009 Noel Yap <noel.yap+code.google.com+com.pwsafe.android@gmail.com>.
 * All rights reserved. Use of the code is allowed under the
 * Artistic License 2.0 terms, as specified in the LICENSE file
 * distributed with this code, or available from
 * http://www.opensource.org/licenses/artistic-license-2.0.php
 */
package org.pwsafe.android;

import edu.cornell.lassp.houle.RngPack.RandomElement;
import edu.cornell.lassp.houle.RngPack.Ranmar;
import edu.cornell.lassp.houle.RngPack.RanMT;

public class TestUtil {
    private static RandomElement mCharacterPrng = new Ranmar();
    private static RandomElement mIntegerPrng = new RanMT();

    public static String createAnonymousHexString() {
        int length = 2*mIntegerPrng.choose(256);

        char[] result = new char[length];

        for (int i = 0; i != length; ++i) {
            int hex = mCharacterPrng.choose(16)-1;

            if (hex < 10) {
                result[i] = (char) ('0' + hex);
            } else {
                result[i] = (char) ('a' + (hex - 10));
            }
        }

        return new String(result);
    }

    public static int createAnonymousInt() {
        return mIntegerPrng.choose(16777216);
    }

    public static String createAnonymousText() {
        int length = mIntegerPrng.choose(256);

        char[] result = new char[length];

        for (int i = 0; i != length; ++i) {
            result[i] = (char) (mCharacterPrng.choose(256)-1);
        }

        return new String(result);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.