Hacker News new | past | comments | ask | show | jobs | submit login

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.




How do you read from a file like that in SQL? I know that this is in "theory" possible but I've never had a legitimate use case where I've needed to do file I/O from my ORM, lol.

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);


/dev/urandom.

Some systems have basically made them equivalent though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: