Is it true that computers can't generate true random?

Well, that’s a bit strong. You could always believe the entire future history of the universe is hiding in every particle somewhere, and each is at all times just following this script, with no need for faster-than-light (or indeed any) communication of the script since everyone already has a copy…

It would be a silly and ultimately meaningless way of looking at things. But if one is dedicated to seeing things deterministically for whatever (probably silly and ultimately misguided) reason, it is an available option.

This is one of those questions that someone could ask you and the answer could spawn anything from someone spouting off “yes, flip a coin” to understanding the meaning of life, the universe, and everything.

Computers can generate true random numbers as far as we are concerned. If you don’t believe me, just buy one of these quantum optics number generator cards for your PC. Just wait for it to be delivered and plug it in to your computer. Done deal. Those are real random numbers and not pseudo-random numbers. I understand the extreme hair-splitting involved in some of this but the fact that you can buy a standard computer card to do it is plenty good enough for me.

I used to use the pseudorandom nature to my advantage. When I was a kid, I’d write my own computer games on an Apple IIe. Back then, memory was at a premium - my computer had 128K of RAM and it was considered a “power system” at the time, and floppy discs held (IIRC) 140K. For games with large (for the day) databases, it wasn’t necessary to save all of the data, merely save the seed and “randomly” regenerate it as needed. As long as you always started with the same seed, the resulting data would be the same.

This is also true. The classic Atari game Pitfall, for instance, fit entirely on a 4 kilobyte cartridge, despite having 255 different screens of action. There’s no way you could fit the entire map on the cartridge (along with all of the game-engine code, sprites, etc.), so it was pseudorandomly generated instead.

Tool assisted speedrunners also use the pseudorandom numbers to their advantage. They will figure out how they have to seed the random generator to make the outcome of any random happening fit their goals.

For a hypothetical example, lets say there’s a boss in the game that randomly decides to use certain attacks. The random number is going to have to be generated from something–usually the time or some controller input. So if they time it right, and use the right inputs, the boss will not use it’s more powerful attacks, meaning it takes much less time to kill. Since a common goal is to find the absolute (as opposed to practical) shortest time possible to complete the game (hence the name speedrunner), this is quite likely to help fulfill their goal.

ETA: Another example you may have actually been more aware of–the random encounter system, very common in older RPGs. If you manipulate the random seed properly, you can make it where you have less encounters. Many games can be rigged where you avoid absolutely all random encounters.

Here’s a cool way to generate actual random numbers: Lava Lamps!

Of course, in newer iterations, lava lamps are no longer used. Instead, they simply take the random noise generated by a CMOS or CCD chip used in digital cameras, but that’s simply not as cool.

nm

I have struggled to get pseudorandom numbers. In one environment, the most versatile method of nesting programming loops causes the same inner-loop sequence of random() outputs to start over again for each outer-loop. The alternative form of random() will return the same value if you call it several times within a brief period, I suspect because it reseeds itself from the clock rather than from its previous output. I have even gone to the trouble of slowly filling an array with random()'s and storing it so I can draw from it quickly when necessary.

I think the coolest way to get random numbers on a computer is to build a contraption out of Lego that throws dice automatically, with a webcam hooked up to the computer to read them and software to count the pips.

Who wrote that random() implementation? :dubious:

The only possible way it could produce the same results repeatedly within a short time frame is if the generator were being re-seeded every time it was called – most likely using the current time in seconds. It should not be re-seeding itself at all, let alone every time it is called!

For most purposes, the proper way to use a PRNG is to seed it once, usually at the start of whatever it is that you’re doing. Seeding multiple times is a great way to reduce the randomness of the distribution, especially if it’s done carelessly. PRNGs are simple beasts. A common variety is the linear congruential generator (LCG), which produces pseudorandom numbers by applying this recurrence relation:


   
        next = (a * next + c) % m;


Where a, c, and m are constants (which should satisfy certain properties for good results; see the article). Seeding the PRNG simply consists of assigning a certain value to next – so you can see that if you constantly reset next, you’re not even really using the generator anymore; your output is only going to be as “random” as the source of your seeds. (Which, in the case of a clock, is not very random at all.)

There should never be any need to do this! Just seed the generator once at the beginning of the program, then call random() every time you need a pseudo-random number. If that doesn’t produce satisfactory results, then this random() is horribly broken and you should probably just use whatever is in the standard libraries for your platform instead.

It might be a very restricted platform (say, an internal scripting language for some application) for which that poorly-implemented function is the standard library version.

Is the LCG the algorithm that results in streaky diagonal lines across the screen if you plot “random” points? That was always a fun exercise in my elementary-school programming days.

Yep, that’s the one.

My go-to PRNG is the Mersenne twister, which has beautiful randomness yet exceptional speed.

MaxTheVool could use a reversible random number generator here: http://boards.straightdope.com/sdmb/showthread.php?t=573760
In his case, he would need to be able to generate the nth random number based on sequence, and in reverse derive the sequence from the random number. His approach was to use a hashing algorithm, so this thread makes me curious about the relationship between PRNGs and hashing. Hashing should ‘randomly’ distribute sequential numbers across a range. These topics have me curious about the relationship between the two concepts of randomness used in these different applications.

It’s a very restricted platform, an internal scripting language for some application, for which that poorly-implemented function is the standard library version.

Oh… Hi, Chronos! Nice to hear from you!

Anyway, I didn’t say what I meant clearly about “reseeding”, but I think you got it. I’m actually using two scripting languages that both apparently share the feature that calling random() without an argument uses a clock value that only updates every few milliseconds as the seed, AND starts the sequence over, so it’s using the fresh seed rather than its previous result.

In one of these languages, there are two ways of doing loops. The simpler method of looping is only allowed inside certain kinds of subroutines, and in this method you normally use random(3034584357) to return random numbers, with some long seed typed by hitting lots of number keys clumsily. This produces a sequence that looks random. However, every time you run the program, it produces the same sequence. Now, the fancier way of looping has the same effect as running that part of the program again and again, including starting the pseudorandom sequence over again. There are actually reasons one might want to do this, but humorously this means there’s really no practical means of just generating pseudorandom numbers that always look random, that are always unpredictable.

Although I’m not an mathematican or expert on chaos theory, I strongly disagree and suggest that you read as soon as possible Poppers essay on this (predictably, I’ve forgotten the title of the essay and the book - but it was about determinsm and free will.) He explains why nothing is pre-determined and thus, why people have free will (I was amazed when I first read it at the approach to use advanced physics to think about free will, instead of the usual philosophic approach.

Anyway, with chaos theory and Heisenberg’S theorem and others, you can’t determine every outcome. You can predict that if you throw a dice it won’t turn into a yellow bird and fly away (unless a wizard passes through), but there are other outcomes besides the six sides, like landing on an edge, or falling of the table and rolling into a corner.:wink:

This reminds me of a chapter in one of the “Science of Discworld…” books (no, these are the serious ones: one of the authors is a respected mathematican). I forgot whether it was 1, 2 or 3, but anyway, the chapter tried to explain why humans suck at random numbers. I have a hard time remembering the whole line of reasoning, but basically I think the argument was:

When you mix a pack of cards and they all appear 2,3,4 etc to ace, each colour seperated, you would not call that random, you would exclude that. However, mathematically, it is random (if you mixed good enough). It’s just that we, as humans, decide that this particular order of cards has meaning, while the other orders (which are just as likely) are “unorderd” and therefore random.

another example with numbers: The sequences

1 2 3 4 5 6 7 8 9

3 1 4 5 …

2 7 1 8 2 8 …

do all look not random (second is pi, third is euler’s number). Again, that’s only because we call certain sequences ordererd and others not. If these sequences had been gotten by throwing a non-weighted ten-sided die = random, we would have a hard time believing it. Following that line, however, every sequence has some meaning. Maybe

53972 is digit 1030 onwards of pi, or the square root of … whatever. If you look hard enough, any sequence has an order, and would therefore be excluded, so you have no randomness at all.

Or something.

That’s not cooler than lava lamps!

Unless, of course, you build your lego contraption out of the Pirate Legos set and toss D&D dice. Now, that would be cool.

Yes. Humans are absolutely hopeless at generating random sequences or deciding if sequences are random (without using some kind of maths).

Some years ago I wrote a music player program. One of it’s functions was to take lists of tracks I liked and copy them to my MP3 player together with a playlist so that they would play in a random order. (It was actually a little more complicated than that because it used three lists so that some tracks would play more frequently than others - dependent upon which list they were in.)

The program worked exactly as designed but I found it quite unusable because the the random tracks seemed so filled with patterns it sounded as if the randomisation wasn’t working.

It actually took a great deal of work to enable the program to come up with a very carefully ordered list (that made no use of randomisation whatsoever) and yet sounds absolutely random to me.

Similar in concept (if maybe not as cool), there’s a web service that supplies random bits fed by radioactive decay.