1

As I understand it, most pseudo-random algorithms work by taking one or more truly random longs, such as the date, time, MAC-Address, serial-number, etc., passing them through a complex series of calculations, and returning the result.

However, this isn't possible in Brainf*ck. The language only has 8 valid syntax characters, but I won't bother you with a full description, which can be found here. The gist is that there aren't any functions to access system time or any other number that I can think of as a seed. I can't think of where to get good seeds to put into functions. Does anyone have any suggestions?

Thanks in advance.

Note: feel free to edit this questions so that it applies to more languages; I just can't put my finger on the right word to use.

  • 2
    Your Brainfuck link is broken. Basically, in order to create a set of pseudo-random numbers that don't repeat, you'll need some way of getting data from the outside world into the program. Functions that read the current time are a common such, but not the only possible. If I recall correctly, the old Apple ][ used the timing of key presses. – Gort the Robot Apr 27 '14 at 22:50

2 Answers2

8

The only input function available to a Brainf*ck program is to read from the standard input. If your program does not need user input, then you could connect stdin to a random device and read random bytes from that. For example:

bf program </dev/urandom
Greg Hewgill
  • 10,181
  • 1
  • 46
  • 45
0

A psuedo-random number generator only appears to be random. It's intended to be uncorrelated with other processes so, e.g. you can use it to generate random test data and then, if needed, fix a bug and reproduce the test.

You can build a random number generator from a psuedo-random number generator by seeding it with external data. It looks like doing that in Brainfuck requires reading characters via the , operator.

Jerry101
  • 5,367
  • 1
  • 15
  • 19