Code example for Random

Methods: nextInt

0
     * 
     * @param words the list of words to which the sentence will be appended. 
     * @param isHeadline whether the sentence must look like a headline or not. 
     */ 
    private void generateSentence(List<String> words, boolean isHeadline) {
        if (!isHeadline && mRandom.nextInt(4) == 0)
            generateTimeClause(words, isHeadline);
        generateAgent(words, isHeadline);
        generatePredicate(words, isHeadline);
    } 
 
    private void generateTimeClause(List<String> words, boolean isHeadline) {
        if (mRandom.nextInt(2) == 0) {
            words.add(pickOneOf("today", "yesterday", "this afternoon", "this morning",
                    "last evening")); 
        } 
        else { 
            words.add(pickOneOf("this", "last"));
            words.add(pickOneOf("Monday", "Tuesday", "Wednesday", "Thursday"));
            words.add(pickOneOf("morning", "afternoon", "evening"));
        } 
    } 
 
    private void generateAgent(List<String> words, boolean isHeadline) {
       if (!isHeadline) {
           words.add(pickOneOf("a", "the"));
       } 
       if (mRandom.nextInt(3) != 0) {
           words.add(pickOneOf(ADJECTIVES));
       } 
       words.add(pickOneOf(THINGS));
    } 
 
    private void generatePredicate(List<String> words, boolean isHeadline) {
        words.add(pickOneOf(isHeadline ? VERBS_PRESENT : VERBS_PAST));
        if (!isHeadline)
            words.add(pickOneOf("a", "the"));
        if (mRandom.nextInt(3) != 0) {
            words.add(pickOneOf(ADJECTIVES));
        } 
        words.add(pickOneOf(THINGS));
 
        if (mRandom.nextInt(3) == 0) {
            words.add(isHeadline ? pickOneOf(", claims", ", says") :
                 pickOneOf(", claimed", ", said", ", reported")); 
            if (!isHeadline)
                words.add(pickOneOf("a", "the"));
            if (mRandom.nextInt(3) != 0) {
                words.add(pickOneOf(ADJECTIVES));
            } 
            words.add(pickOneOf(THINGS));
        } 
    } 
 
    private String pickOneOf(String ... options) {
        return options[mRandom.nextInt(options.length)];
    } 
 
    private static String joinWords(List<String> words) {
        int i;
        if (words.size() == 0) {