我正在寻找代码,在深奥的语言脑中为一个存储单元分配一个伪随机数***。我找到了this sample code,但发现它有点令人困惑。据我所知,它是一个"需要一些装配" (没有双关语?)样本。运行它会导致接近无限循环。我还看过this question和维基百科的文章,但仍然有些困惑。
我正在寻找一个可以运行的简单代码段。我不在乎它是否会影响周围的细胞。我只要求对样本进行充分评论。
答案 0 :(得分:1)
我在你提到的那个页面上使用了算法,为我正在编写的脑跳编译器实现了一个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的单元格不会被任何其他代码触及,因为它们包含随机数种子(每次运行此代码时都会更改)
答案 1 :(得分:1)
BrainfuckMachine IDE附带的代码示例对我来说很有效。
>>>++[
<++++++++[
<[<++>-]>>[>>]+>>+[
-[->>+<<<[<[<<]<+>]>[>[>>]]]
<[>>[-]]>[>[-<<]>[<+<]]+<<
]<[>+<-]>>-
]<.[-]>>
]
"Random" byte generator using the Rule 30 automaton.
Doesn't terminate; you will have to kill it.
To get x bytes you need 32x+4 cells.