Files
SDK_SG200x_V2/fsbl/lib/BigDigits/t_bdQuickRandBits.c
carbon 0545e9dc6d init version 2024-05-07
commit d1edce71135cc6d98c0a4b5729774542b676e769
Author: sophgo-forum-service <forum_service@sophgo.com>
Date:   Fri Mar 15 16:07:33 2024 +0800

    [fix] recommend using ssh method to clone repo.
    [fix] fix sensor driver repo branch name.
2024-05-07 19:36:36 +08:00

66 lines
1.9 KiB
C

/* $Id: t_bdQuickRandBits.c $ */
/***** BEGIN LICENSE BLOCK *****
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright (c) 2001-16 David Ireland, D.I. Management Services Pty Limited
* <http://www.di-mgt.com.au/bigdigits.html>. All rights reserved.
*
***** END LICENSE BLOCK *****/
/*
* Last updated:
* $Date: 2016-03-31 09:51:00 $
* $Revision: 2.6.1 $
* $Author: dai $
*/
/*
What is the difference between bdQuickRandBits and bdRandomBits?
bdRandomBits() uses the "pretty-good" internal RNG and requires you to include bigdRand.h
and compile with bigdRand.c and bigdigitsRand.c.
You can be pretty sure that the numbers generated will pass all statistical tests for randomness.
bdQuickRandBits() just needs the standard bigd.h include file and you do not need to
add the modules bigdRand.c and bigdigitsRand.c to your project.
It uses the stdlib rand() function, which is by no means secure, but it will quickly fill up a number
with the required number of random-looking bits.
It might repeat if you call twice in quick succession. It's quick and dirty, as advertised.
If you *really* want a secure random number, then use bdRandomSeeded() and call your own super-secure
random number generator, throwing in your own bit of extra entropy with the seed.
*/
#include <stdio.h>
#include <assert.h>
#include "bigd.h"
#include "bigdRand.h"
int main(void)
{
BIGD a;
int i;
a = bdNew();
// Test bdQuickRandBits (quick-and-dirty)
printf("Testing bdQuickRandBits...\n");
for (i = 0; i < 10; i++)
{
bdQuickRandBits(a, 128);
bdPrintHex("", a, "\n");
}
// Test bdRandomBits (more secure)
printf("Testing bdRandomBits...\n");
for (i = 0; i < 10; i++)
{
bdRandomBits(a, 128);
bdPrintHex("", a, "\n");
}
return 0;
}