feat: add random

This commit is contained in:
2025-09-19 00:03:05 +08:00
parent 16b45b8016
commit ca09d56fe4
2 changed files with 40 additions and 0 deletions

31
single-scripts/random.ts Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env runts -- --allow-read
import { parseArgs } from "jsr:@std/cli/parse-args";
const flags = parseArgs(Deno.args, {
boolean: ["help"],
string: ["length"],
});
if (flags.help) {
console.log("random.ts [--post-message] [--length <length>]");
Deno.exit(0);
}
const len = parseInt(flags.length || "12", 10);
const buffer = new Uint8Array(len);
const file = await Deno.open("/dev/random", { read: true });
try {
const nread = await file.read(buffer);
if (nread == null) {
throw "Read from /dev/random failed";
}
} finally {
file.close();
}
Deno.stdout.write(buffer);
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250919T000056+08:00.MEUCIQD0uwOh8xr+8Oog7x6s
// cUutQYrO4oFkS+SU1mZogTFuwAIgE7PWbiDvzAKFUSCc0byrdwWkXrcJp+7CDWr3+e83Zy4=