I'm really confused by this post. Wouldn't it be simpler to read a few bytes from /dev/random?
Sure, it wouldn't be portable to windows but that's more of a feature than a bug.
Sure, it wouldn't be portable to windows but that's more of a feature than a bug.
This is the ChatGPT answer that I was able to derive:
> You can read from `/dev/urandom` in a PostgreSQL query using `plperlu`, which allows executing unsafe Perl code. > Create a function to read random bytes:
CREATE EXTENSION plperlu;
CREATE OR REPLACE FUNCTION get_random_bytes(num_bytes int)
RETURNS bytea
LANGUAGE plperlu
AS $$
my $num_bytes = $_[0];
open my $urandom, '<', '/dev/urandom' or die "Cannot open /dev/urandom: $!";
read $urandom, my $bytes, $num_bytes;
close $urandom;
return $bytes;
$$;
SELECT get_random_bytes(16);Some systems have basically made them equivalent though.