Created
September 9, 2022 11:14
-
-
Save Reijaff/d72a2245d3bda3d119a4a170c680a109 to your computer and use it in GitHub Desktop.
primitive compile time random number generation in zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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