Skip to content

Instantly share code, notes, and snippets.

@Reijaff
Created September 9, 2022 11:14
Show Gist options
  • Select an option

  • Save Reijaff/d72a2245d3bda3d119a4a170c680a109 to your computer and use it in GitHub Desktop.

Select an option

Save Reijaff/d72a2245d3bda3d119a4a170c680a109 to your computer and use it in GitHub Desktop.
primitive compile time random number generation in zig
const std = @import("std");
const RndGen = std.rand.DefaultPrng;
fn rand_at_comptime() u32 {
var rnd = RndGen.init(1337);
var a = rnd.random().int(u32);
return a;
}
pub fn main() !void {
var c_ = comptime rand_at_comptime();
const stdout = std.io.getStdOut().writer();
try stdout.print("{any}\n", .{c_});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment