2 * Copyright (c) 2008, 2009 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
29 static bool inited = false;
33 if (gettimeofday(&tv, NULL) < 0) {
34 ovs_fatal(errno, "gettimeofday");
36 srand(tv.tv_sec ^ tv.tv_usec);
41 random_bytes(void *p_, size_t n)
60 if (RAND_MAX >= UINT16_MAX) {
65 random_bytes(&x, sizeof x);
73 if (RAND_MAX >= UINT32_MAX) {
76 } else if (RAND_MAX == INT32_MAX) {
78 return rand() | ((rand() & 1u) << 31);
81 random_bytes(&x, sizeof x);
89 return random_uint32() % max;