Java Code Examples for com.hippo.yorozuya.MathUtils#random()

The following examples show how to use com.hippo.yorozuya.MathUtils#random() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Settings.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@NonNull
private static String generateUserID() {
    int length = LENGTH_USER_ID;
    StringBuilder sb = new StringBuilder(length);

    for (int i = 0; i < length; i++) {
        if (MathUtils.random(0, ('9' - '0' + 1) + ('z' - 'a' + 1)) <= '9' - '0') {
            sb.append((char) MathUtils.random('0', '9' + 1));
        } else {
            sb.append((char) MathUtils.random('a', 'z' + 1));
        }
    }

    return sb.toString();
}
 
Example 2
Source File: ACSite.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
private ACCdnPath getCdnPath() {
    final float r = MathUtils.random(mRateSum);
    float sum = 0.0f;
    List<ACCdnPath> list = mCdnPathList;
    ACCdnPath cdnPath = null;
    for (int i = 0, size = list.size(); i < size; i++) {
        cdnPath = list.get(i);
        sum += cdnPath.rate;
        if (r <= sum) {
            return cdnPath;
        }
    }
    return cdnPath;
}
 
Example 3
Source File: Settings.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public static @NonNull String getRandomFeedId() {
    int length = 20;
    StringBuilder sb = new StringBuilder(length);

    for (int i = 0; i < length; i++) {
        if (MathUtils.random(0, 1 + 1) == 0) {
            sb.append((char) MathUtils.random('a', 'z' + 1));
        } else {
            sb.append((char) MathUtils.random('0', '9' + 1));
        }
    }

    return sb.toString();
}
 
Example 4
Source File: Settings.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@NonNull
private static String generateUserID() {
    int length = LENGTH_USER_ID;
    StringBuilder sb = new StringBuilder(length);

    for (int i = 0; i < length; i++) {
        if (MathUtils.random(0, ('9' - '0' + 1) + ('z' - 'a' + 1)) <= '9' - '0') {
            sb.append((char) MathUtils.random('0', '9' + 1));
        } else {
            sb.append((char) MathUtils.random('a', 'z' + 1));
        }
    }

    return sb.toString();
}
 
Example 5
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
public void getXuMing() {
    int click = mClick;
    // Get xu ming
    if (click % 10 < 9 || MathUtils.random(1.0f) < 0.95f) {
        switch (click / 10) {
            case 0:
                mXuMing = 1000;
                mXuMingStr = "+1s";
                break;
            case 1:
                mXuMing = 60 * 1000;
                mXuMingStr = "+1m";
                break;
            case 2:
                mXuMing = 60 * 60 * 1000;
                mXuMingStr = "+1h";
                break;
            default:
                mXuMing = 24 * 60 * 60 * 1000;
                mXuMingStr = "+1d";
                break;
        }
    } else {
        switch (click / 10) {
            case 0:
                mXuMing = -10 * 1000;
                mXuMingStr = "-10s";
                break;
            case 1:
                mXuMing = -10 * 60 * 1000;
                mXuMingStr = "-10m";
                break;
            case 2:
                mXuMing = -10 * 60 * 60 * 1000;
                mXuMingStr = "-10h";
                break;
            default:
                mXuMing = -10 * 24 * 60 * 60 * 1000;
                mXuMingStr = "-10d";
                break;
        }
        mClick = 0;
    }
}
 
Example 6
Source File: MarqueeReplyView.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
private long getMarqueeInterval() {
    return MathUtils.random(3000, 5001);
}