gpt4 book ai didi

algorithm - BF - 生成伪随机数

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:50:56 25 4
gpt4 key购买 nike

我正在寻找用深奥的语言 brainf*** 将伪随机数分配给存储单元的代码。我找到了 this sample code ,但发现它有些困惑。据我所知,这是一个“需要一些组装”(不是双关语?)样本。运行它会导致近乎无限循环。我也已经看过 this question 和维基百科文章,但仍然有些困惑。

我正在寻找可以运行的简单代码段。我不在乎它是否会影响它周围的细胞。我只要求 sample 得到很好的评论。

最佳答案

我曾使用您提到的那个页面上的算法为我正在编写的 brainfuck 编译器实现 RNG。那里的代码不太难使用。把所有的变量名都放在里面(比如 temp0、temp1、randomh、randoml 等)并给它们一个数字。这将是该变量的单元格编号。然后,您只需为变量插入必要的 > 和 < 符号。这是第一部分的示例。 temp0 到 temp5 的单元格编号为 0 到 5,randomh 为 6,randoml 为 7:

pointer starts at 0

pointer is at 0 and need to go to temp0 (cell 0) so do nothing
temp0 [-]
pointer is at 0 and need to go to temp1 (at cell 1) so move one position to the right
temp1 >[-]
pointer is at 1 and need to go to temp2 (at cell 2) so move another position to the right
temp2 >[-]
pointer at 2 and needs to go to 3 so move another position to the right
temp3 >[-]
pointer at 3 and needs to go to 4 so move another position to the right
temp4 >[-]
pointer at 4 and needs to go to 5 so move another position to the right
temp5 >[-]

pointer at 5 and needs to go to 6 so move one to the right
randomh >[
pointer at 6 and needs to go to 0 so move 6 to the left
temp0 <<<<<<+
pointer at 0 and needs to go to 6 so move 6 to the right
randomh >>>>>>-]

然后您继续为代码中的每个变量执行此操作。此算法的重要之处在于,分配给 randomh 和 randoml 的单元格不会被任何其他代码触及,因为它们包含随机数种子(每次运行此代码时都会更改)

关于algorithm - BF - 生成伪随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23283966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com