Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include <liboil/liboil.h>
22 #include <liboil/liboildebug.h>
27 #include <liboil/globals.h>
29 #define LOG_FILE "c:\\logs\\examples_oil-random_log.txt"
30 #include "std_log_result.h"
31 #define LOG_FILENAME_LINE __FILE__, __LINE__
33 void create_xml(int result)
38 testResultXml("examples_oil-random");
41 typedef struct _OilRandomState OilRandomState;
43 struct _OilRandomState {
51 static void _oil_random_init (void);
52 uint32_t oil_random_get_int (OilRandomState *state);
53 void oil_random_get_bits (OilRandomState *state, uint8_t *dest, int n);
55 int main (int argc, char *argv[])
65 std_log(LOG_FILENAME_LINE,"%d\n", oil_random_get_int(&state));
68 oil_random_get_bits (&state, (void *)a, 10*4);
70 std_log(LOG_FILENAME_LINE,"%d\n", a[i]);
73 std_log(LOG_FILENAME_LINE,"Test Fail");
75 std_log(LOG_FILENAME_LINE,"Test Successful");
82 oil_random_state_seed (OilRandomState *state, uint32_t seed)
84 uint32_t *mt = state->mt;
89 mt[i] = (1812433253UL * (mt[i-1] ^ (mt[i-1] >> 30)) + i);
91 oil_mt19937 (state->bits, state->mt);
98 _oil_random_init (void)
103 OIL_ERROR("seed is %d", seed);
105 oil_random_state_seed (&state, seed);
109 oil_random_get_int (OilRandomState *state)
111 if (state->index >= 624) {
112 oil_mt19937 (state->bits, state->mt);
115 return state->bits[state->index++];
119 oil_random_get_bits (OilRandomState *state, uint8_t *dest, int n)
121 int i = state->index * 4;
126 oil_mt19937 (state->bits, state->mt);
131 if (m > 624*4 - i) m = 624*4 - i;
133 memcpy (dest, ((uint8_t *)state->bits) + i, m);
137 state->index = (i+3)/4;