dimanche 16 avril 2017

Split value into two random numbers

I'm creating a random book catalogue in Java and I intend to split a randomly generated price value of a book package into TWO separate values (representing the individual packages for two books).

For eg. A randomly generated book package 42 costs $80 and the individual prices of the two books in that package cost $X and $Y. Here's an excerpt of my code:

void buildCatalogue() {

    int numItems = rand.nextInt(maxNumItems);
    while (bookCatalogue.size() < numItems) {
        int ranID = rand.nextInt(maxBookID);
        bookCatalogue.put(String.valueOf(ranID), rand.nextInt(maxBookPrice));

    }

    for (Object key : bookCatalogue.keySet()) {

System.out.println("Package ID: " + (String) key + "; price value: " + bookCatalogue.get(key)); //The individual values of the two books should print here
    }

}

How do I split the generated price value into two random values?




Aucun commentaire:

Enregistrer un commentaire