algorithm - BF - 生成伪随机数

标签 algorithm random brainfuck esoteric-languages

我正在寻找用深奥的语言 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/

相关文章:

python - 如何反向循环?

Python sklearn RandomForestClassifier 不可重现的结果

windows - Windows批处理文件中的 "for"循环中的随机变量没有改变

python - '~' 在 python 中是什么意思?

while-loop - 在brainfuck中高效实现while循环

java - 为什么 Kotlin 解释 Brainfuck 的速度比 Java 快得多?

c++ - A* 搜索中的 "Jumping"

javascript - 在完成此最佳拟合算法时需要帮助

algorithm - 使用三中位数的快速排序改进 Robert sedwick

python - 加快随机数据的创建