$RandomGeneratorState
给出默认随机数生成器的内部状态的表示.
更多信息
- $RandomGeneratorState 返回一个 RandomGeneratorState 对象,可将其传递给 BlockRandom、SeedRandom 及相关函数.
范例
打开所有单元 关闭所有单元应用 (1)
创建一个版本的 BlockRandom,如果无法恢复当前的随机状态,则拒绝运行:
SetAttributes[myBlockRandom, HoldFirst];
myBlockRandom[args__] := If[$RandomGeneratorState["StateHash"] =!= None,
BlockRandom[args],
"Aborting as the active method has no restorable state."]SeedRandom["Method" -> "OpenSSL"]因为无法对此方法播种,BlockRandom 无法给出可重现的结果:
SeedRandom[1234, "Method" -> "OpenSSL"]myBlockRandom[RandomReal[]]SeedRandom["Method" -> "ExtendedCA"]myBlockRandom[RandomReal[]]myBlockRandom[RandomReal[]]属性和关系 (4)
$RandomGeneratorState 返回一个 RandomGeneratorState 对象:
$RandomGeneratorState//Head月 RandomInteger、RandomReal 及相关函数改变 $RandomGeneratorState:
$RandomGeneratorState使用 RandomComplex:
RandomComplex[]$RandomGeneratorState可用 SeedRandom 恢复 $RandomGeneratorState 的值:
state = $RandomGeneratorState;
RandomInteger[100, 10]SeedRandom[state];
RandomInteger[100, 10]在计算结束后恢复 $RandomGeneratorState 实际上相当于 BlockRandom:
Table[Block[{state, result}, state = $RandomGeneratorState;result = RandomInteger[100];SeedRandom[state];result], {5}]Table[BlockRandom[RandomInteger[100]], {5}]文本
Wolfram Research (2020),$RandomGeneratorState,Wolfram 语言函数,https://reference.wolfram.com/language/ref/$RandomGeneratorState.html.
CMS
Wolfram 语言. 2020. "$RandomGeneratorState." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/$RandomGeneratorState.html.
APA
Wolfram 语言. (2020). $RandomGeneratorState. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/$RandomGeneratorState.html 年
BibTeX
@misc{reference.wolfram_2026_$randomgeneratorstate, author="Wolfram Research", title="{$RandomGeneratorState}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/$RandomGeneratorState.html}", note=[Accessed: 14-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_$randomgeneratorstate, organization={Wolfram Research}, title={$RandomGeneratorState}, year={2020}, url={https://reference.wolfram.com/language/ref/$RandomGeneratorState.html}, note=[Accessed: 14-August-2026]}