如何在Visual C ++ 2005 Express中使用System :: Random? [英] How to use System::Random in Visual C++ 2005 Express?

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

问题描述

我正在尝试使用随机数生成器而rand()只是没有

直到任务(RAND_MAX太小了)。


我在帮助系统中搜索并找到了System :: Random类

这似乎是完美的。

然而,由于一些奇怪的原因,帮助文件只是拒绝告诉

什么应该#included才能使用该类。我无法在任何地方找到这个

信息!即使是帮助中给出的示例程序也缺少这个

信息(因此当然也没有编译)。

我试过谷歌搜索,但无济于事。我无法在任何地方找到这个信息


I''m trying to use a random number generator and rand() is just not
up to the task (RAND_MAX is way too small).

I searched in the help system and found the System::Random class
which seems to be just perfect.
However, for some odd reason the help files simply refuse to tell
what should be #included in order to use the class. I can''t find this
info anywhere! Even the example program given in the help lacks this
information (and thus of course doesn''t compile).
I have tried google-searching, to no avail. I can''t find this info
anywhere.

推荐答案

4月4日下午12:32,Juha Nieminen < nos ... @ thanks.invalidwrote:
On Apr 4, 12:32 pm, Juha Nieminen <nos...@thanks.invalidwrote:

我正在尝试使用随机数生成器而rand()只是没有

直到任务(RAND_MAX太小了)。


我在帮助系统中搜索并找到了System :: Random类

哪个似乎是完美的。

然而,由于一些奇怪的原因,帮助文件只是拒绝告诉

为了使用该类应该#included。我无法在任何地方找到这个

信息!即使是帮助中给出的示例程序也缺少这个

信息(因此当然也没有编译)。

我试过谷歌搜索,但无济于事。我无法在任何地方找到这个信息


I''m trying to use a random number generator and rand() is just not
up to the task (RAND_MAX is way too small).

I searched in the help system and found the System::Random class
which seems to be just perfect.
However, for some odd reason the help files simply refuse to tell
what should be #included in order to use the class. I can''t find this
info anywhere! Even the example program given in the help lacks this
information (and thus of course doesn''t compile).
I have tried google-searching, to no avail. I can''t find this info
anywhere.



这几乎是因为System :: Random在.NET中(例如C ++ /

CLI)因此不是真正的c ++或与此组相关(您可以尝试

microsoft.public.dotnet.languages.vc)。当然,如果我错了,

有人在System命名空间中定义了一些Random类。发布

示例,我们肯定会知道。

That''s pretty much because System::Random is in .NET land (e.g. C++/
CLI) thus not really c++ or related to this group (you could try
microsoft.public.dotnet.languages.vc). Of course in case I''m wrong and
someone defined some Random class in a System namespace .. post the
example and we''ll know for sure.


4月4日,11:32,Juha Nieminen< nos ... @ thanks.invalidwrote:
On 4 Apr, 11:32, Juha Nieminen <nos...@thanks.invalidwrote:

我正在尝试使用随机数生成器而rand()只是没有

直到任务(RAND_MAX太小了)。

我在帮助系统中搜索并找到了System :: Random类

这似乎是完美的。

然而,由于一些奇怪的原因,帮助文件只是拒绝告诉

什么应该#included才能使用该类。我无法在任何地方找到这个

信息!即使是帮助中给出的示例程序也缺少这个

信息(因此当然也没有编译)。

我试过谷歌搜索,但无济于事。我无法在任何地方找到这个信息


I''m trying to use a random number generator and rand() is just not
up to the task (RAND_MAX is way too small).

I searched in the help system and found the System::Random class
which seems to be just perfect.
However, for some odd reason the help files simply refuse to tell
what should be #included in order to use the class. I can''t find this
info anywhere! Even the example program given in the help lacks this
information (and thus of course doesn''t compile).
I have tried google-searching, to no avail. I can''t find this info
anywhere.



System :: Random是.Net框架的一部分,您必须创建一个

托管项目才能使用它。但请注意,使用此类内容意味着您的代码不再是纯C ++,而是供应商特定的

扩展名。

有很多方法可以使用rand(),你可以调用rand()两次和

乘以数字,运行它多次并添加结果直到你

得到一个足够大的结果,将rand()的结果乘以一些

因子来缩放它,依此类推。根据您的计划使用

随机数,某些方法比其他方法更好。


-

Erik Wikstr ?m

System::Random is part of the .Net framework and you must create a
managed project to use it. Notice however that using such things means
that your code is no longer pure C++, but rather a vendor-specific
"extension".

There are ways to make do with rand(), you can call rand() twice and
multiply the numbers, run it many times and add the results until you
get a result big enough, multiply the result of rand() with some
factor to scale it, and so on. Depending on what you plan to use the
random number for some approaches are better than others.

--
Erik Wikstr?m


" Erik Wikstr?m" < er **** @ student.chalmers.sewrote in message

news:11 ********************* @ o5g2000hsb。 googlegrou ps.com ...

4月4日,11:32,Juha Nieminen< nos ... @ thanks.invalidwrote:
"Erik Wikstr?m" <er****@student.chalmers.sewrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...

On 4 Apr, 11:32, Juha Nieminen <nos...@thanks.invalidwrote:

我正在尝试使用随机数生成器而rand()只是没有

直到任务(RAND_MAX太小了)。


我在帮助系统中搜索并找到了System :: Random类

这似乎是完美的。

然而,由于一些奇怪的原因帮助文件只是拒绝告诉

什么应该#included才能使用该类。我无法在任何地方找到这个

信息!即使是帮助中给出的示例程序也缺少这个

信息(因此当然也没有编译)。

我试过谷歌搜索,但无济于事。我无法在任何地方找到这个信息


I''m trying to use a random number generator and rand() is just not
up to the task (RAND_MAX is way too small).

I searched in the help system and found the System::Random class
which seems to be just perfect.
However, for some odd reason the help files simply refuse to tell
what should be #included in order to use the class. I can''t find this
info anywhere! Even the example program given in the help lacks this
information (and thus of course doesn''t compile).
I have tried google-searching, to no avail. I can''t find this info
anywhere.



System :: Random是.Net框架的一部分,您必须创建一个

托管项目才能使用它。但请注意,使用此类内容意味着您的代码不再是纯C ++,而是供应商特定的

扩展名。

有很多方法可以使用rand(),你可以调用rand()两次和

乘以数字,运行它多次并添加结果直到你

得到一个足够大的结果,将rand()的结果乘以一些

因子来缩放它,依此类推。根据您计划使用的内容

随机数比某些方法更好。


[pjp]或者,如果您需要更高质量的随机分布,请参阅Boost中的

随机包。它也是TR1的一部分,这意味着你

将它作为我们的Compleat Libraries的一部分。


PJ Plauger

Dinkumware,Ltd。
http://www.dinkumware.com


这篇关于如何在Visual C ++ 2005 Express中使用System :: Random?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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