1// Copyright 2016 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <inttypes.h> 6#include <stdio.h> 7#include <stdint.h> 8#include <zircon/status.h> 9#include <zircon/syscalls.h> 10 11#define TRIALS 10000 12#define BINS 32 13 14int main(int argc, char** argv) { 15 static uint8_t buf[32]; 16 uint64_t values[BINS] = { 0 }; 17 18 zx_cprng_draw(&buf, sizeof(buf)); 19 20 printf("Drew %zd bytes: ", sizeof(buf)); 21 for (unsigned int i = 0; i < sizeof(buf); ++i) { 22 printf(" %02x", buf[i]); 23 } 24 printf("\n"); 25 26 for (unsigned int i = 0; i < TRIALS; ++i) { 27 uint8_t byte; 28 zx_cprng_draw(&byte, 1); 29 values[byte % BINS]++; 30 } 31 32 for (unsigned int i = 0; i < BINS; ++i) { 33 printf("bin %u: %" PRIu64 "\n", i, values[i]); 34 } 35 36 return 0; 37} 38