Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/helper/test-genrandom.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / helper / test-genrandom.c` 37 lines ยท 857 bytes Raw Blame History 1 /* 2 * Simple random data generator used to create reproducible test files. 3 * This is inspired from POSIX.1-2001 implementation example for rand(). 4 * Copyright (C) 2007 by Nicolas Pitre, licensed under the GPL version 2. 5 */ 6 7 #include "test-tool.h" 8 #include "git-compat-util.h" 9 #include "parse.h" 10 11 int cmd__genrandom(int argc, const char **argv) 12 { 13 unsigned long count, next = 0; 14 unsigned char *c; 15 16 if (argc < 2 || argc > 3) { 17 fprintf(stderr, "usage: %s []\n", argv[0]); 18 return 1; 19 } 20 21 c = (unsigned char *) argv[1]; 22 do { 23 next = next * 11 + *c; 24 } while (*c++); 25 26 count = ULONG_MAX; 27 if (argc == 3 && !git_parse_ulong(argv[2], &count)) 28 return error_errno("cannot parse argument '%s'", argv[2]); 29 30 while (count--) { 31 next = next * `1103515245` + 12345; 32 if (putchar((next >> 16) & 0xff) == EOF) 33 return -1; 34 } 35 36 return 0; 37 }