summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/trandom.c
blob: 23602375b43d992834e22a61114c622253c38099 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    trandom.c

Abstract:

    Test program for the random number generator

Author:

    Gary Kimura     [GaryKi]    26-May-1989

Revision History:

--*/

#include <stdio.h>

#include <nt.h>
#include <ntrtl.h>

int
_CDECL
main(
    int argc,
    char *argv[]
    )
{
    ULONG Seed;
    ULONG Temp;
    ULONG i;
    CHAR Str[64];

    DbgPrint("Start IntegerToChar and CharToInteger Test\n");

    Seed = 0x12345678;
    RtlIntegerToChar(Seed, 2, sizeof(Str), Str);
    DbgPrint("Seed = 0b%s\n", Str);
    RtlCharToInteger(Str, 2, &Temp);
    ASSERTMSG( "RtlCharToInteger(2)", (Seed == Temp) );

    RtlIntegerToChar(Seed, 8, sizeof(Str), Str);
    DbgPrint("Seed = 0o%s\n", Str);
    RtlCharToInteger(Str, 8, &Temp);
    ASSERTMSG( "RtlCharToInteger(8)", (Seed == Temp) );

    RtlIntegerToChar(Seed, 10, sizeof(Str), Str);
    DbgPrint("Seed = %s\n", Str);
    RtlCharToInteger(Str, 10, &Temp);
    ASSERTMSG( "RtlCharToInteger(10)", (Seed == Temp) );

    RtlIntegerToChar(Seed, 16, -8, Str);
    Str[ 8 ] = '\0';
    DbgPrint("Seed = 0x%s\n", Str);
    RtlCharToInteger(Str, 16, &Temp);
    ASSERTMSG( "RtlCharToInteger(16)", (Seed == Temp) );

    DbgPrint("End IntegerToChar and CharToInteger Test\n");

    DbgPrint("Start RandomTest()\n");

    Seed = 0;
    for (i=0; i<2048; i++) {
        if ((i % 3) == 0) {
            DbgPrint("\n");
        }

        RtlRandom(&Seed);
        DbgPrint("%p ", Seed);

        RtlIntegerToChar(Seed, 16, sizeof(Str), Str);
        DbgPrint("= %s ", Str);

    }

    DbgPrint("\n");

    DbgPrint("End RandomTest()\n");

    return TRUE;

}