/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/zig/zig-520-103-001/main.zig
19 строк
630 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
const std = @import("std"); const random = std.crypto.random; pub fn generatePassword(allocator: std.mem.Allocator, len: usize) ![]u8 { const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var buf = try allocator.alloc(u8, len); for (buf) |*c| { c.* = charset[random.intRangeAtMost(usize, 0, charset.len - 1)]; } return buf; } pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const pass = try generatePassword(gpa.allocator(), 16); defer gpa.allocator().free(pass); std.debug.print("{s}\n", .{pass}); }