我如何在C#中使用随机数? [英] How do I use random numbers in C#?

查看:109
本文介绍了我如何在C#中使用随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的傍在C#W / XNA。

I'm working on Pong in C# w/ XNA.

我想用一个随机数(范围内),以确定的东西,如否皮球反弹直,或倾斜,以及速度有多快球移动时,它击中桨。

I want to use a random number (within a range) to determine things such as whether or not the ball rebounds straight, or at an angle, and how fast the ball moves when it hits a paddle.

我想知道如何实现它。

推荐答案

使用的随机类。例如:

Random r = new Random();
int nextValue = r.Next(0, 100); // Returns a random number from 0-99

这篇关于我如何在C#中使用随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆