It can’t. At least an algorithm alone can’t.
For “mundane” purposes, you just use a “kinda random” source of data like the last digits of the current time in milliseconds, the processor clock speed or the mouse cursor position, and then run it through a chaotic function (one that maps similar inputs to completely different outputs, but is still predictable). This is called a PRNG, or pseudo random number generator.
For security critical purposes, you have to use something else but software. And people get creative here: there’s for example a literal wall of lava lamps with a webcam pointed at it, and that webcam’s video stream is the randomness source.
Obligatory Tom Scott video: https://www.youtube.com/watch?v=1cUUfMeOijg
Latest Answers