aboutsummaryrefslogtreecommitdiffstats
path: root/btrfs-crc.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2016-05-26 10:56:51 +0800
committerDavid Sterba <dsterba@suse.com>2016-06-03 14:49:42 +0200
commit2171228b200bfd1e1c9e993f7cac6567e6c94609 (patch)
tree8ca0feb88597cab357f4f5f3a64bef7ebf2cb389 /btrfs-crc.c
parent17239a9c89dec5576784675edd205264535c1557 (diff)
downloadbtrfs-progs-2171228b200bfd1e1c9e993f7cac6567e6c94609.tar.gz
btrfs-progs-2171228b200bfd1e1c9e993f7cac6567e6c94609.tar.xz
btrfs-progs-2171228b200bfd1e1c9e993f7cac6567e6c94609.zip
btrfs-progs: Use new random number API
Replace old and not so informal srand()/rand() calls to new random number API. Including btrfs-corrupt-block(main user), btrfs-image and btrfs-crc. Some tests like dir-test/random-test/quick-test is not modified. As random-test itself can't even pass build. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-crc.c')
-rw-r--r--btrfs-crc.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/btrfs-crc.c b/btrfs-crc.c
index 723e0b7..1ef00eb 100644
--- a/btrfs-crc.c
+++ b/btrfs-crc.c
@@ -40,7 +40,7 @@ int main(int argc, char **argv)
char *str;
char *buf;
int length = 10;
- int seed = getpid() ^ getppid();
+ u64 seed = 0;
int loop = 0;
int i;
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
loop = 1;
break;
case 's':
- seed = atol(optarg);
+ seed = atoll(optarg);
break;
case 'h':
usage();
@@ -77,11 +77,12 @@ int main(int argc, char **argv)
buf = malloc(length);
if (!buf)
return -ENOMEM;
- srand(seed);
+ if (seed)
+ init_rand_seed(seed);
while (1) {
for (i = 0; i < length; i++)
- buf[i] = rand() % 94 + 33;
+ buf[i] = rand_range(94) + 33;
if (crc32c(~1, buf, length) == checksum)
printf("%12lu - %.*s\n", checksum, length, buf);
}