The Math.random() Questions (4 days)

  1. Write a method that will print out 10 random numbers between 1 and 100.
    public void printTen()
  2. Write a method that will receive two numbers and will then return out a random number between the two (inclusively)
    public int getNumber(int lo, int hi)
  3. Write a method that will generate 50 random numbers between 1 and 100 and will then print out the sum and the average .
    public void printStats()
  4. Write a program that will pick a number between 1 and 100 and then let you guess the number. It will tell you that you got it (and end program) or tell you your guess was too high or too low and let you continue guessing.
    public guessingGame()
  5. Simulate the rolling of a pair of dice 100 times. How many times did you roll 7?
    public int numberOfSevens()
  6. Simulate the flipping of a coin 1000 times. How many times was it heads.
    public int numberOfHeads()
  7. Simulate a fortune teller. You push a key and 1 of 5 fortunes comes out.
    public void printFortunes()
  8. Monte Carlo Approximation - If I start with 48 dice and roll them and remove all 2's, how many rolls will it take until all the dice are removed. Run simulation (with a loop) 1 million times and find the average of how many rolls it would take on average.
    public double getRolls()
  9. Print out 1 of 6 names at random.
    public void printName()
  10. Print out a number at random between 1 and 37 public void printNumber1()
  11. Between -100 and 100
    public void printNumber2()
  12. Between -15 and 25
    public void printNumber3()
  13. Between -30 and -20
    public void printNumber4()
  14. Between -1 and 1
    public void printNumber5()
  15. Either -1 or 1
    public void printNumber6()
  16. 3, 5 or 7
    public void printNumber7()
  17. Write a method that will generate 50 random numbers between 1 and 100 and print out the average, the smallest number and the biggest number.
    public void printStuff()
  18. Write a method that will print out a random addition problem (numbers between 1 and 37) and will let you type in an answer and will then tell you if you are right or wrong.
    public void mathProblem()
    12 + 4 =
  19. Write a method that will print out 5 even numbers at random between 1 and 100.
    public void print5Even()
  20. Write a method that will do the same as number 18 except that it will ask you 10 random math questions and then give you a score at the end (use a loop)
  21. Rolling Two in a Row: Write a program that rolls a die 1000 times and counts the number of times the same result occurs twice in a row. In your counting, you should consider a sequence 3 3 3 as containing two sets of identical rolls -- the middle 3 matches the first, and the third 3 matches the second. Thus, the following sequence of rolls would be counted as having the same result occur twice in a row for 4 times.

    1 5 3 2 4 4 6 5 5 5 3 6 2 1 1 2

    public int twiceinarow()
  22. Write a program that will generate 2 random integers between 1 and 100 that when multiplied togeteher equals 4221. Print the answer and return how many tries it took the computer to get the result?

    public int getCount()
  23. Three coins are tossed 100,000 times. What is the probability that the first head is flipped on the third toss. (what % of the time will this occur)

    public int getPercent()
  24. Same as above except, what is the probability that no heads are tossed.

    public int getPercent2()
  25. As a code to get into her bank account SAM JONES used 3 random letters from his name (Ex. NES, ASA). Write a method that will keep generating 3 letter strings from his name until it matches the target password. Return how many attempts it took to find the key and print out what the key was.

    private String key = "MAJ";

    public int printKey()
  26. Simulate the rolling of 4 dice. What percentage of the time will you get at least 1 match?