Java ID Value Create generateId()

Here you can find the source of generateId()

Description

Generates a random, valid id to use when fetching a fact.

License

Open Source License

Return

the generated id

Declaration

static int generateId() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    /**// w  ww  . j  a  v a 2  s. c o m
     * Generates a random, valid id to use when fetching a fact.
     * @return the generated id
     */
    static int generateId() {
        Random rand = new Random();
        int id = rand.nextInt(989) + 1;

        // Fact numbers 498 through 650 no longer exist on Snapple's website
        // Make sure to get a new random number if it falls within this range
        while (id > 497 && id < 651) {
            id = rand.nextInt(989) + 1;
        }

        return id;
    }
}

Related

  1. createID()
  2. createID()
  3. generateId()
  4. generateId()
  5. generateId()
  6. generateID(final String message)
  7. generateID(int seed)