Tricky dice Download

Christina Cacioppo

ints, random, control statements Idea sketch


Introduction

The oldest dice seem to have been used, 5000 years ago, to play backgammon in Iran. Those dice were made from animal's hooves; now, dice tend to made of plastic or code.


Task

Below is a simple script that uses Java's built in random number generator to make a dice. Specifically, it:

  1. Creates a new Random number generator, and saves it in a variable called gen.
  2. Asks gen to give its next integer in the range [0, 6). Then, we add 1 to what the nextInt function returns, because we want our dice to give back 1, 2, 3, 4, 5, or 6.

That makes a normal dice from code.

Let's make a tricky dice instead. It's up to you how to do this, but there's a few rules (even for tricky die):

  1. A dice is "tricky" when the likelihood of it giving back a 1, 2, 3, 4, 5, or 6 isn't equivalent – as in, it'll give back a 6 more than 18.33% of the time (on average.)
  2. Your dice can only give back 1, 2, 3, 4, 5, or 6 – we want this to seem like a valid dice at first.
  3. Which numbers your dice over-emphasizes, and which it understates, is entirely up to you.``


Starter code

class Dice{
	public static void rollTrickyDice(){
		/*		Your code here		*/
	}

	public static void rollFairDice(){
		Random gen = new Random();
		int roll = gen.nextInt(6) + 1;
		System.out.println("Fair dice rolls a " + roll);
	}

	public static void main(String[] args){
		for(int i = 0; i < 5; i++){
			rollFairDice();
			rollTrickyDice();
			System.out.println("-----")
		}
	}
}

Expected output

Fair dice rolls a 5
Tricky dice rolls a 2
-----
Fair dice rolls a 3
Tricky dice rolls a 2
-----
Fair dice rolls a 1
Tricky dice rolls a 3
-----
Fair dice rolls a 4
Tricky dice rolls a 2
-----
Fair dice rolls a 2
Tricky dice rolls a 2
-----

Hints



Useful tools to solve the problem