Question

Write a script that prints a randomly generated integer between 1 and 6. When I run...

  1. Write a script that prints a randomly generated integer between 1 and 6. When I run your script, it should print out only the number that would appear on the die like this:
    5
    and nothing else.
  2. Write a script that takes input for the number of sides on the die. An n sided die should return a random integer between 1 and n with the same stipulations as in Exercise 1. You should take n from the user as typed input. Output should be the same as in #1.
  3. Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this:
    6,4,1,3,1
  4. HARD: Write a script that will simulate the roll of an UNFAIR 6-sided die. Instead of each side having an even chance of coming up (1/6 = 16.7%), the middle numbers should be favored. There should be a 20% chance of rolling a 2, 3, 4, or 5, and only a 10% chance of rolling a 1 or a 6. Hint: You will need the round function and some other simple math. This is hard because of the thinking involved, not because of the coding; in fact, you can write it in one (sort of complex) line of code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

a)

clc
clear all
close all
n=randi([1,6],1,1)

b)

clc
clear all
close all
n=input('Enter number of sides: ');
randi([1,n],1,1)

c)

clc
clear all
close all
n=input('Enter number of sides: ');
num=input('Number of times to roll? ');
v=[];
for i=1:num
v(i)=randi([1,n],1,1);
end
fprintf('%d,',v(1:end-1));
fprintf('%d\n',v(end));

Note: Brother According to Chegg's policy we are only allowed to answer first 3 part if there are many. So, I request you to post other part as separate posts

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a script that prints a randomly generated integer between 1 and 6. When I run...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game....

    Use C++ 11 to write the program War Game Requirement Setting This is a 2-player game. It is played through dice. Rule for scoring The player who rolls higher number gets one point. If both players roll the same number, it is considered a draw and no one gets a point. Dice Specification There are two kinds of dice: normal die, represented by Die class. loaded die, represented by the loadedDie class. Classes Die class Die class has a member...

  • Complete each problem separately and perform in python. 1. Create a script that will roll five...

    Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...

  • Python Script format please! 1. Write a script that takes in three integer numbers from the...

    Python Script format please! 1. Write a script that takes in three integer numbers from the user, calculates, and displays the sum, average, product, smallest, and largest of the numbers input. Important things to note: a. You cannot use the min() or max() functions, you must provide the logic yourself b. The calculated average must be displayed as an integer value (ex. If the sum of the three values is 7, the average displayed should be 2, not 2.3333). Example:...

  • Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

    Modular program mathlab: Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “You got it” If the user’s die is smaller, it should display, “Nice try” If the results are the...

  • (CO 4 and 6) Create a program with a function named rollDice that will roll a...

    (CO 4 and 6) Create a program with a function named rollDice that will roll a dice as many times as the user asks and with a user specified number of sides. The function should return the roll of the die. The program should continue while the user presses Y.    Sample output: How many times do you want to roll the die? 5 How many sides does the die have: 6 You rolled 1 You rolled 2 You rolled...

  • I am having some trouble writing this program. In C language Write a program which asks...

    I am having some trouble writing this program. In C language Write a program which asks user 1) number of sets (integer input), followed by 2) number of sides of a dice (integer input) and 3) number of dices (integer input). number of sets mean how many times this process is going to repeat, number of sides mean total number of sides in a dice (usually 6) and number of dices mean how many number of dices we’re going to...

  • WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...

    WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot. Pig Dice Game Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount...

  • Can anyone help me with this java program? We are still very early with lessons so...

    Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class             The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT