问题描述
我喜欢新的Swift 4.2 RandomNumberGenerator,但是我看不到有种子的可能性.我是否缺少某些东西,或者是否有可能通过调用底层低级函数来播种这些生成器?我有很多代码,它们在默认数字类型上使用默认数字生成器,现在我需要确保每次启动之间的行为完全相同,并且代码更改应尽可能少.
I like the new Swift 4.2 RandomNumberGenerator thing, but I don't see a seed possibility there. Am I missing something, or is there any way at all to seed these generators, by maybe calling an underlying low-level function? I have a lot of code, which uses default number generators on default number types, and I now need to make sure that everything behaves exactly the same between launches with as little code changes as possible.
推荐答案
新架构的整体思想是,只要采用RandomNumberGenerator协议,任何生成器都可以被替换.因此,如果您需要可重复的种子,请使用自己的随机生成器算法.
The whole idea of the new architecture is that any generator can be substituted just by adopting the RandomNumberGenerator protocol. So if you need a repeatable seed, use your own random generator algorithm.
这篇关于有没有一种方法可以让Swift 4.2随机数生成器成为种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!