-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MacSerial, Codecs.plist, pic.ids update
- Loading branch information
1 parent
279644d
commit b9f9afc
Showing
9 changed files
with
820 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.46 KB
(100%)
...deproj/project.xcworkspace/xcuserdata/headsoft.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** @file | ||
Copyright (c) 2020, vit9696. All rights reserved. | ||
SPDX-License-Identifier: BSD-3-Clause | ||
**/ | ||
|
||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
#ifdef __GNUC__ | ||
uint32_t arc4random(void) __attribute__((weak)); | ||
uint32_t arc4random_uniform(uint32_t upper_bound) __attribute__((weak)); | ||
#endif | ||
|
||
// Taken from https://en.wikipedia.org/wiki/Xorshift#Example_implementation | ||
// I am not positive what is better to use here (especially on Windows). | ||
// Fortunately we only need something only looking random. | ||
uint32_t pseudo_random(void) { | ||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) | ||
if (arc4random) | ||
return arc4random(); | ||
#endif | ||
|
||
static uint32_t state; | ||
|
||
if (!state) { | ||
fprintf(stderr, "Warning: arc4random is not available!\n"); | ||
state = (uint32_t)time(NULL); | ||
} | ||
|
||
uint32_t x = state; | ||
x ^= x << 13; | ||
x ^= x >> 17; | ||
x ^= x << 5; | ||
state = x; | ||
return x; | ||
} | ||
|
||
// Taken from https://opensource.apple.com/source/Libc/Libc-1082.50.1/gen/FreeBSD/arc4random.c | ||
// Mac OS X 10.6.8 and earlier do not have arc4random_uniform, so we implement one. | ||
uint32_t pseudo_random_between(uint32_t from, uint32_t to) { | ||
uint32_t upper_bound = to + 1 - from; | ||
|
||
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__) | ||
// Prefer native implementation if available. | ||
if (arc4random_uniform) | ||
return from + arc4random_uniform(upper_bound); | ||
#endif | ||
|
||
uint32_t r, min; | ||
|
||
if (upper_bound < 2) | ||
return from; | ||
|
||
#if (ULONG_MAX > 0xffffffffUL) | ||
min = 0x100000000UL % upper_bound; | ||
#else | ||
if (upper_bound > 0x80000000) | ||
min = 1 + ~upper_bound; | ||
else | ||
min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; | ||
#endif | ||
|
||
for (;;) { | ||
r = pseudo_random(); | ||
if (r >= min) | ||
break; | ||
} | ||
|
||
return from + r % upper_bound; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @file | ||
Copyright (c) 2020, vit9696. All rights reserved. | ||
SPDX-License-Identifier: BSD-3-Clause | ||
**/ | ||
|
||
#ifndef OC_USER_PSEUDO_RANDOM_H | ||
#define OC_USER_PSEUDO_RANDOM_H | ||
|
||
#include <stdint.h> | ||
|
||
uint32_t pseudo_random(void); | ||
uint32_t pseudo_random_between(uint32_t from, uint32_t to); | ||
|
||
#endif // OC_USER_PSEUDO_RANDOM_H |
Oops, something went wrong.