dice

44.double dice roll

做~自己de王妃 提交于 2019-12-30 18:08:46
问题描述 解决骰子滚动后,我们已经知道如何将介于0.0和1.0之间的小数值转换为特定范围内的整数-例如,转换为介于1和6之间的数值,以模拟掷骰子。 但是,许多编程语言(例如C / C ++,PHP,Pascal)都使用随机数生成器,而随机数生成器仅给出从0到最大最大值之间的整数值。如何将这些数字转换为骰子点? 碰巧这种情况更简单。我们可以使用以下方法: 将随机值R除以N(我们想要的不同值的数量-例如,骰子为6),然后取剩余的值。该余数必须是0到N-1范围内的整数。 现在将其移至必要的范围,只需加1(即我们想要的范围的最小值)即可,您将获得介于1到N之间的值。 如果N与发生器的最大值相比不够小,则此方法的精度不太高。但是,对于大多数日常需求(扔硬币,掷骰子,洗牌等)都可以。 为了进行练习,让我们继续以下练习: 1输入数据将在第一行中包含测试用例(掷骰子)的数量。 2接下来的行将具有测试用例,每个用例都由两个随机整数组成,用于抛出一对骰子。这些数字是非负数(从0到大于2,000,000,000的某个值),应使用上面建议的算法将它们转换为骰子点。 3答案应包含一对骰子每次掷出的总和,值之间应用空格隔开 测试案例 input data: 7 193170145 1912748246 753156389 614113621 1824520917 53700559 1288077384

Python - rolling a dice fairly and counting how many 4's I get

那年仲夏 提交于 2019-12-25 18:19:10
问题 So I had to make code that roll a die fairly and counted how many 4's I got. With the help of you all on here I got it to work. Well now I have to created another die and roll them and then add they products together. This is the instructions I've been given. "Then write another function that simulates rolling two fair dice. The easy way is to call the function you just wrote, twice, and add the numbers you get. This should return a number between 2 and 12. It should calculate BOTH numbers in

for loop dice roll and textbox.Text updating troubles c#

大憨熊 提交于 2019-12-25 14:33:26
问题 I'm trying to make a program where there is at first a random dice roll that is "rolls" to decide the number of times that dicethrow should throw the dice (between 1 and 9 times), anything greater than rolls should be the end of the game. I also need the score to update after every roll, which is what I was trying to do in the comments, but I'm not sure if I would need to TryParse the wagerTextBox.Text to get a value and prevent format exceptions, or if it would be fine without it (or where I

Using a do-while to restart a game in java

爱⌒轻易说出口 提交于 2019-12-25 07:31:19
问题 Please help with the swtich case need for a game public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Please Enter a number"); int day = input.nextInt(); switch(day) { case 1: System.out.println("1 Microphone"); break; case 2: System.out.println("2 Loud Speakers 1 Microphone "); break; case 3: System.out.println("3 Keyboards 2 Loudspeakers 1 Microphone "); break; case 4: System.out.println("4 Java Books 3 Keyboards 2 Loudspeakers 1 Microphone");

Python In-Between Dice Game Loops

落花浮王杯 提交于 2019-12-25 02:47:53
问题 I have an issue with an In-Between dice game I'm writing. I had another question posted before which was answered, but I still have a problem. (Bear in mind I'm VERY new to programming in general) Here is the output I'm getting, it involves the 'higher or lower' option that appears if the two dice roll the same number: Would you like to play in-between [y|n]? y Die 1: 1 Die 2: 1 Number of chips: 100 Place your bet: 50 Even-steven! Even-steven! Higher or lower [h|l]? h Die 3: 9 * You win! *

使用pygal统计投掷N次骰子之后点数的分布情况

天大地大妈咪最大 提交于 2019-12-16 20:21:15
一、环境信息 python版本:2.7.13 pygal版本:2.4.0 pygal安装:pip install pygal 从python官方完整下载的最新的python版本自带pip 二、具体实现 投掷N次骰子,然后统计每个点数出现的数字。首先需要实现的是随机点数,具体代码如下: dice.py # -*- coding: utf-8 -*- #pip install pygal from random import randint class Dice(): """表示一个骰子的类""" def __init__(self, number_sides=6): """骰子默认为6面,称之为D6;如果是8面的骰子称之为D8""" self.number_sides = number_sides def roll(self): """返回一个位于1和骰子面数之间的随机值""" return randint(1, self.number_sides) 1、投掷一个6面的骰子(D6)10000次,查看每个点数的统计结果: dice_visual.py # -*- coding: utf-8 -*- import pygal from dice import Dice #掷一个骰子 #创建一个D6 dice = Dice() #将结果存储在一个列表中 results = [] for

Dice rolling simulator in Python

岁酱吖の 提交于 2019-12-14 03:28:12
问题 I want to write a program that rolls a dice. Now this is what I have : import random print("You rolled",random.randint(1,6)) And I also want to be able to do something like this: print("Do you want to roll again? Y/N") and then if I press Y it rolls again and if I press N I quit the app. Thanks in advance! 回答1: Let's walk through the process: You already know what you need to generate random numbers. import random (or you could be more specific and say from random import randint , because we

C++ Simple Dice roll - how to return multiple different random numbers [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-13 23:51:25
问题 This question already has answers here : How does calling srand more than once affect the quality of randomness? (5 answers) Closed 2 years ago . I am pretty new to C++ and am trying to make a simple die roll with a Die class/main. I can get a random number within my range 1-dieSize, however, each time I "roll the dice" it just gives me the same random number. For example, when I roll this dice three times, it will cout 111 or 222 etc instead of 3 different random rolls. Any help explaining

Basic C++ Dice game

南笙酒味 提交于 2019-12-13 11:15:24
问题 I have a problem here, would be really nice if anyone could help me out here. Its my first time using this program so dont be to judgemental. #include <cstdlib> #include <iostream> using namespace std; int throw1, throw2, throw3, throw4; int bet1 = 100; int bet2 = 300; int bet3 = 500; int bet=(bet1, bet2, bet3); int deposit; int account; int main(){ int count = 0; while(count < 3){ cin>>deposit; while(deposit>5000 || deposit<0){ //Makes sure so that my deposit is between 0-5000 cout<<"deposit

How to put dice rolls in an array? [closed]

左心房为你撑大大i 提交于 2019-12-13 07:57:07
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Dear stackoverflowers, Could someone help me further with this excercise: Throw a dice 40 times. The throws has to be put in an array. If a throw is the same as the previous one, it has to be grouped between brackets. It'll cost you 1 point per throw, and if you throw two the same numbers in a row, you get 5