Silverlight System.随机排序跨平台
我需要知道不同平台对 System.Random 对象 (Silverlight) 的影响。在 Mac、PC 和 32 / 64 位上创建的序列是否相同?
I need to know the effect of different platforms on the System.Random
object (Silverlight). Is the sequence created the same on Mac, PC and across 32 / 64 bit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请原谅我的“愚蠢”答案,但在我看来,随机数应始终被视为随机,因此创建的序列应在任何“域”中处理为不相同。我知道 .NET(或 Silverlight)随机数生成器根据种子值使用伪随机算法,并且在使用相同种子值时会生成相同的数字序列,但我只是不会依赖这一事实。
当您需要在多个平台上同步随机数时,您似乎有某种“期望”,并且使用随机数生成器来生成期望值序列对我来说看起来很奇怪。
如果您能告诉我们更多有关您的用例的信息,也许我们可以找到另一个更可靠的解决方案?
只是我的意见。
Excuse my "stupid" answer, but to my mind, Random numbers should be always considered random and thus the created sequences should be handled as NOT same across any "domain". I know that the .NET (or Silverlight) random number generators use a Pseudo-random algorithm depending on the seed value and will generate the same number sequence when using the same seed value, but I just wouldn't rely on this fact.
It seems that you have some kind of "expectation" when you need to have random numbers synchronized across several platforms, and using a Random Number generator for expected value sequences looks weird to me.
If you can tell us more about your use case, maybe we can find another more solid solution?
Just my opinion.
生成随机数的算法被编码到运行时中。因此,无论平台如何,您都应该看到给定种子值的同一组“随机”数字。
Random
的默认构造函数(其中种子值基于时间)的确切行为可能因平台而略有不同。例如,快速创建“随机”实例可能会创建一些生成相同序列的实例,这些“重复项”的分布可能会因包括平台在内的各种条件而有所不同。The algorithm to generate the random numbers is encoded into the runtime. Hence regardless of the platform you should see the same set of "random" numbers for a given seed value.
The extact behaviour of default constructor for
Random
(where the seed value is time based) may vary slightly from platform to platform. For example rapid creation of instances ofRandom
may create some instances that generate the same sequence, the distribution of these "duplicates" may vary on all sorts of conditions including the platform.