2021-09-13 20:11:12 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
File: AuRandomDevice.cpp
|
2021-09-13 20:11:12 +00:00
|
|
|
Date: 2021-9-3
|
|
|
|
Author: Reece
|
|
|
|
***/
|
2021-09-06 10:58:08 +00:00
|
|
|
#include <AuroraRuntime.hpp>
|
2022-11-17 07:46:07 +00:00
|
|
|
#include "AuRandomDevice.hpp"
|
2021-09-06 10:58:08 +00:00
|
|
|
|
|
|
|
namespace Aurora::RNG
|
|
|
|
{
|
2023-12-04 21:11:32 +00:00
|
|
|
static const double kDblEpsilon = 2.2204460492503131e-16;
|
|
|
|
|
2024-01-03 23:52:57 +00:00
|
|
|
RandomDevice::RandomDevice() :
|
|
|
|
IO::Adapters::RandomStreamReader(AuUnsafeRaiiToShared(this))
|
2023-10-17 09:03:15 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-03 23:52:57 +00:00
|
|
|
RandomDevice::RandomDevice(const RandomDef &def) :
|
|
|
|
IO::Adapters::RandomStreamReader(AuUnsafeRaiiToShared(this))
|
2023-10-17 09:03:15 +00:00
|
|
|
{
|
|
|
|
this->Init(def);
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
void RandomDevice::Init(const RandomDef &def)
|
|
|
|
{
|
|
|
|
this->def_ = def;
|
2022-09-19 01:34:57 +00:00
|
|
|
|
|
|
|
// Gross...
|
2022-09-27 16:30:26 +00:00
|
|
|
if (!def.bSecure)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2021-10-01 16:54:55 +00:00
|
|
|
if (def.seed)
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
this->fast_ = AuMove(WELL_SeedRand(def.seed.value()));
|
2021-10-01 16:54:55 +00:00
|
|
|
}
|
|
|
|
else if (def.seed64)
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
this->fast_ = AuMove(WELL_SeedRand64(def.seed64.value()));
|
2021-10-01 16:54:55 +00:00
|
|
|
}
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
else if (def.seedMassive)
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
this->fast_ = AuMove(WELL_SeedRandBig64(def.seedMassive.value()));
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
}
|
2021-10-01 16:54:55 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-20 20:43:37 +00:00
|
|
|
RNG::RngFillArray<false>(this->fast_.state);
|
2021-10-01 16:54:55 +00:00
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
// secure rng requires no init -> we just passthrough to the global ReadSecureRNG function
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
void RandomDevice::Read(Memory::MemoryViewWrite view)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
if (!view)
|
2022-11-17 07:46:07 +00:00
|
|
|
{
|
|
|
|
SysPushErrorArg();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:30:26 +00:00
|
|
|
if (this->def_.bSecure)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
ReadSecureRNG(view);
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-15 06:05:22 +00:00
|
|
|
WELL_NextBytes(&this->fast_, view.ptr, AuUInt32(view.length));
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
AuString RandomDevice::NextString(AuUInt32 uLength, ERngStringCharacters type)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2022-11-17 07:46:07 +00:00
|
|
|
AuString ret(uLength, '\00');
|
2022-06-14 15:59:37 +00:00
|
|
|
NextString(ret.data(), AuUInt32(ret.size()), type);
|
2021-09-06 10:58:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
static double RngConvertToDecimal(AuUInt64 uLargeInt)
|
|
|
|
{
|
|
|
|
AuUInt64 qwValue = (uLargeInt & 0xFFFFFFFFFFFFFull) | 0x3FF0000000000000ull;
|
|
|
|
return *(double *)(&qwValue) - 1.0;
|
|
|
|
}
|
2023-11-18 01:45:12 +00:00
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
void RandomDevice::NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
static AuPair<const char *, int> rngSequence[static_cast<int>(ERngStringCharacters::eEnumCount)] =
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
|
|
|
{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 52},
|
|
|
|
{"abcdefghijklmnopqrstuvwxyz", 26},
|
|
|
|
{"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26},
|
|
|
|
{"1234567890", 10},
|
|
|
|
{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", 62},
|
2024-03-11 17:33:36 +00:00
|
|
|
{"abcdefghijklmnopqrstuvwxyz1234567890", 36},
|
|
|
|
{"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", 36},
|
2023-11-18 01:45:12 +00:00
|
|
|
{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890=-+!$%^*.[];:", 75}
|
2021-09-06 10:58:08 +00:00
|
|
|
};
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
if (!pString)
|
|
|
|
{
|
|
|
|
SysPushErrorArg();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-28 03:59:09 +00:00
|
|
|
Read(AuMemoryViewWrite { pString, uLength });
|
2021-09-06 10:58:08 +00:00
|
|
|
|
[*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.
[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
Catch,
Submission,
LockError,
NoAccess,
ResourceMissing,
ResourceLocked,
MalformedData,
InSandboxContext,
ParseError
[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors
et al
2022-02-17 00:11:40 +00:00
|
|
|
if (!ERngStringCharactersIsValid(type))
|
|
|
|
{
|
|
|
|
SysPushErrorArg("NextString was called with an invalid ERngStringCharacters {}", (AuUInt)type);
|
|
|
|
type = ERngStringCharacters::eAlphaNumericCharacters; // guess we cant just return false
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
const auto &pair = rngSequence[static_cast<int>(type)];
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
for (auto i = 0u; i < uLength; i++)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(pair.second);
|
2023-11-18 01:45:12 +00:00
|
|
|
AuUInt8 uNext {};
|
|
|
|
auto uWord = reinterpret_cast<const AuUInt8 *>(pString)[i];
|
|
|
|
while ((uNext = (uWord & (uUpperBound - 1))) >= pair.second)
|
|
|
|
{
|
|
|
|
uWord = AuFnv1a32Runtime(&uWord, sizeof(uWord));
|
|
|
|
}
|
|
|
|
pString[i] = pair.first[uNext];
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt8 RandomDevice::NextByte()
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
if (this->def_.bSecure)
|
|
|
|
{
|
|
|
|
AuUInt8 uRet {};
|
|
|
|
ReadSecureRNG({ &uRet, 1 });
|
|
|
|
return uRet;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return AuUInt8(WELL_NextLong(&this->fast_) & 0xFF);
|
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
bool RandomDevice::NextBoolean()
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
if (this->def_.bSecure)
|
|
|
|
{
|
|
|
|
AuUInt8 uRet {};
|
|
|
|
ReadSecureRNG({ &uRet, 1 });
|
|
|
|
return bool(uRet & 0x1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return bool(WELL_NextLong(&this->fast_) & 0x1);
|
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt32 RandomDevice::NextU32()
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
if (this->def_.bSecure)
|
|
|
|
{
|
|
|
|
AuUInt32 uRet {};
|
|
|
|
ReadSecureRNG({ &uRet, 4 });
|
|
|
|
return uRet;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return WELL_NextLong(&this->fast_);
|
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt64 RandomDevice::NextU64()
|
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
if (this->def_.bSecure)
|
|
|
|
{
|
|
|
|
AuUInt64 uRet {};
|
|
|
|
ReadSecureRNG({ &uRet, 8 });
|
|
|
|
return uRet;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NextFillTmpl<AuUInt64>();
|
|
|
|
}
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuInt32 RandomDevice::NextI32Range(AuInt32 iMin, AuInt32 iMax)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2024-04-22 05:02:56 +00:00
|
|
|
auto uRange = AuUInt32(iMax - iMin);
|
2023-11-15 17:53:37 +00:00
|
|
|
auto uMassiveWord = NextU32();
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
2023-11-15 17:53:37 +00:00
|
|
|
AuUInt32 uNext {};
|
2023-11-17 08:19:26 +00:00
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
2023-11-15 17:53:37 +00:00
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a32Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2023-11-15 17:53:37 +00:00
|
|
|
}
|
2024-04-22 05:02:56 +00:00
|
|
|
return iMin + uNext;
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
AuUInt32 RandomDevice::NextU32Range(AuUInt32 uMin, AuUInt32 uMax)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
auto uRange = uMax - uMin;
|
|
|
|
auto uMassiveWord = NextU32();
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
2023-11-15 17:53:37 +00:00
|
|
|
AuUInt32 uNext {};
|
2023-11-17 08:19:26 +00:00
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
2023-11-15 17:53:37 +00:00
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a32Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2023-11-15 17:53:37 +00:00
|
|
|
}
|
|
|
|
return uMin + uNext;
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 03:04:26 +00:00
|
|
|
// Source: https://stackoverflow.com/a/5016867
|
|
|
|
bool RandomDevice::DecGeometric(int x)
|
|
|
|
{
|
|
|
|
if (x <= 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
auto r = this->NextByte();
|
|
|
|
|
|
|
|
if (x < 8)
|
|
|
|
{
|
|
|
|
return (r & ((1 << x) - 1)) == 0;
|
|
|
|
}
|
|
|
|
else if (r != 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
x -= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Source: https://stackoverflow.com/a/5016867
|
|
|
|
double RandomDevice::UniformFloatInRange(double udMin, double udMax)
|
|
|
|
{
|
2024-04-22 05:02:56 +00:00
|
|
|
// No....
|
2023-12-01 03:04:26 +00:00
|
|
|
#if defined(AURNG_USE_GARBAGE_DECIMALS)
|
|
|
|
return (double(this->NextU32()) * (double(1.0) / double(AuNumericLimits<AuUInt32>::max()))) * udMax;
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
// No....
|
2024-01-01 14:10:42 +00:00
|
|
|
#elif defined(AURNG_USE_UNIFORM_DECIMALS)
|
2024-04-22 05:02:56 +00:00
|
|
|
|
2023-12-01 03:04:26 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
double f;
|
|
|
|
AuUInt64 u;
|
|
|
|
} convert;
|
|
|
|
|
|
|
|
convert.f = udMin;
|
|
|
|
auto uABits = convert.u;
|
|
|
|
convert.f = udMax;
|
|
|
|
auto uBBits = convert.u;
|
|
|
|
|
|
|
|
auto uMask = uBBits - uABits;
|
|
|
|
uMask |= uMask >> 1;
|
|
|
|
uMask |= uMask >> 2;
|
|
|
|
uMask |= uMask >> 4;
|
|
|
|
uMask |= uMask >> 8;
|
|
|
|
uMask |= uMask >> 16;
|
|
|
|
uMask |= uMask >> 32;
|
|
|
|
|
|
|
|
int bExp {};
|
|
|
|
frexp(udMax, &bExp);
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
int iXExp {};
|
|
|
|
double x;
|
|
|
|
|
|
|
|
auto uXBits = this->NextU64();
|
|
|
|
uXBits &= uMask;
|
|
|
|
uXBits += uABits;
|
|
|
|
if (uXBits >= uBBits)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert.u = uXBits;
|
|
|
|
x = convert.f;
|
|
|
|
frexp(x, &iXExp);
|
|
|
|
|
|
|
|
if (DecGeometric(bExp - iXExp))
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
}
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
// Yes...
|
2024-01-01 14:10:42 +00:00
|
|
|
#else
|
|
|
|
#if !defined(AURNG_USE_FAST_DECIMALS)
|
|
|
|
#define AURNG_USE_FAST_DECIMALS
|
|
|
|
return 0.0;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuInt32> RandomDevice::NextArrayI32Range(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax)
|
|
|
|
{
|
|
|
|
AuList<AuInt32> ret;
|
|
|
|
AuList<AuUInt32> rngBytes;
|
|
|
|
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
auto uRange = AuUInt32(iMax - iMin);
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
2024-01-01 14:10:42 +00:00
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uMassiveWord = rngBytes[uIndex];
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a32Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-01-01 14:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = iMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-22 20:54:05 +00:00
|
|
|
AuList<AuInt32> RandomDevice::NextArrayI32RangeFast(AuUInt32 uCount, AuInt32 iMin, AuInt32 iMax)
|
|
|
|
{
|
|
|
|
AuList<AuInt32> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
auto uRange = AuUInt32(iMax - iMin);
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
auto uSeed = this->NextU32();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a32Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
while ((uNext = (uSeed & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a32Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = iMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
AuList<AuUInt32> RandomDevice::NextArrayU32Range(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax)
|
|
|
|
{
|
|
|
|
AuList<AuUInt32> ret;
|
|
|
|
AuList<AuUInt32> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
auto uRange = uMax - uMin;
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
2024-01-01 14:10:42 +00:00
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uMassiveWord = rngBytes[uIndex];
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a32Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-01-01 14:10:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = uMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-22 20:54:05 +00:00
|
|
|
AuList<AuUInt32> RandomDevice::NextArrayU32RangeFast(AuUInt32 uCount, AuUInt32 uMin, AuUInt32 uMax)
|
|
|
|
{
|
|
|
|
AuList<AuUInt32> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
auto uRange = uMax - uMin;
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
auto uSeed = this->NextU32();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a32Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
while ((uNext = (uSeed & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a32Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = uMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
AuList<double> RandomDevice::NextArrayDoubleRange(AuUInt32 uCount, double dMin, double dMax)
|
|
|
|
{
|
|
|
|
#if defined(AURNG_USE_FAST_DECIMALS)
|
|
|
|
AuList<double> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
double dRange = dMax - dMin;
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
double dValue = RngConvertToDecimal(rngBytes[uIndex]);
|
|
|
|
dValue *= dRange;
|
|
|
|
dValue += dMin;
|
|
|
|
ret[uIndex] = dValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#else
|
|
|
|
AuList<double> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
ret[uIndex] = this->NextNumber(dMin, dMax);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuList<double> RandomDevice::NextArrayDoubleRangeFast(AuUInt32 uCount, double dMin, double dMax)
|
|
|
|
{
|
|
|
|
AuList<double> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
AuUInt64 uSeed = this->NextU64();
|
|
|
|
double dRange = dMax - dMin;
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
double dValue = RngConvertToDecimal(uSeed);
|
|
|
|
dValue *= dRange;
|
|
|
|
dValue += dMin;
|
|
|
|
ret[uIndex] = dValue;
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<8>(&uSeed);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
AuList<AuInt32> RandomDevice::NextArrayI32(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<AuInt32> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt32> RandomDevice::NextArrayU32(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<AuUInt32> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuUInt64 RandomDevice::NextU64Range(AuUInt64 uMin, AuUInt64 uMax)
|
|
|
|
{
|
|
|
|
auto uRange = uMax - uMin;
|
|
|
|
auto uMassiveWord = NextU64();
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a64Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
return uMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuInt64 RandomDevice::NextI64Range(AuInt64 iMin, AuInt64 iMax)
|
|
|
|
{
|
|
|
|
auto uRange = AuUInt64(iMax - iMin);
|
|
|
|
auto uMassiveWord = NextU64();
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
AuUInt32 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a64Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
return iMin + uNext;
|
|
|
|
}
|
|
|
|
|
2024-04-22 20:54:05 +00:00
|
|
|
AuList<AuInt64> RandomDevice::NextArrayI64RangeFast(AuUInt32 uCount, AuInt64 iMin, AuInt64 iMax)
|
|
|
|
{
|
|
|
|
AuList<AuInt64> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
auto uRange = AuUInt64(iMax - iMin);
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
auto uSeed = this->NextU64();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
AuUInt64 uNext {};
|
|
|
|
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
while ((uNext = (uSeed & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = iMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt64> RandomDevice::NextArrayU64RangeFast(AuUInt32 uCount, AuUInt64 uMin, AuUInt64 uMax)
|
|
|
|
{
|
|
|
|
AuList<AuUInt64> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
auto uRange = uMax - uMin;
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
auto uSeed = this->NextU64();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
AuUInt64 uNext {};
|
|
|
|
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
while ((uNext = (uSeed & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<sizeof(uSeed)>(&uSeed);
|
2024-04-22 20:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = uMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuVec2 RandomDevice::NextVec2(AuVec2 boundA, AuVec2 boundB)
|
|
|
|
{
|
|
|
|
AuVec2 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
return NextVec2Sorted(mins, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuVec2 RandomDevice::NextVec2Sorted(AuVec2 min, AuVec2 max)
|
|
|
|
{
|
|
|
|
AuVec2 range;
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
|
|
|
|
auto uSeed = this->NextU64();
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
return AuVec2 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
AuVec3 RandomDevice::NextVec3(AuVec3 boundA, AuVec3 boundB)
|
|
|
|
{
|
|
|
|
AuVec3 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
return NextVec3Sorted(mins, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuVec3 RandomDevice::NextVec3Sorted(AuVec3 min, AuVec3 max)
|
|
|
|
{
|
|
|
|
AuVec3 range;
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
|
|
|
|
auto uSeed = this->NextU64();
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
return AuVec3 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
AuVec4 RandomDevice::NextVec4(AuVec4 boundA, AuVec4 boundB)
|
|
|
|
{
|
|
|
|
AuVec4 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
mins[3] = AuMin(boundA[3], boundB[3]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
maxs[3] = AuMax(boundA[3], boundB[3]);
|
|
|
|
return NextVec4Sorted(mins, maxs);
|
|
|
|
}
|
|
|
|
|
|
|
|
AuVec4 RandomDevice::NextVec4Sorted(AuVec4 min, AuVec4 max)
|
|
|
|
{
|
|
|
|
AuVec4 range;
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
range[3] = max[3] - min[3];
|
|
|
|
|
|
|
|
auto uSeed = this->NextU64();
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentD = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
return AuVec4 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2],
|
|
|
|
(dComponentD * range[3]) + min[3]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuInt64> RandomDevice::NextArrayI64Range(AuUInt32 uCount, AuInt64 iMin, AuInt64 iMax)
|
|
|
|
{
|
|
|
|
AuList<AuInt64> ret;
|
|
|
|
AuList<AuInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
auto uRange = AuUInt64(iMax - iMin);
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uMassiveWord = rngBytes[uIndex];
|
|
|
|
AuUInt64 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a64Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = iMin + uRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt64> RandomDevice::NextArrayU64Range(AuUInt32 uCount, AuUInt64 uMin, AuUInt64 uMax)
|
|
|
|
{
|
|
|
|
AuList<AuUInt64> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
auto uRange = uMax - uMin;
|
|
|
|
auto uUpperBound = AuRoundUpPow2(uRange + 1);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uMassiveWord = rngBytes[uIndex];
|
|
|
|
AuUInt64 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) > uRange)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a64Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret[uIndex] = uMin + uNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt32> RandomDevice::NextArrayU32Mask(AuUInt32 uCount, AuUInt32 uMask)
|
|
|
|
{
|
|
|
|
AuList<AuUInt32> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
for (auto &word : ret)
|
|
|
|
{
|
|
|
|
word &= uMask;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt64> RandomDevice::NextArrayU64Mask(AuUInt32 uCount, AuUInt64 uMask)
|
|
|
|
{
|
|
|
|
AuList<AuUInt64> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
for (auto &word : ret)
|
|
|
|
{
|
|
|
|
word &= uMask;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuInt64> RandomDevice::NextArrayI64(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<AuInt64> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuUInt64> RandomDevice::NextArrayU64(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<AuUInt64> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec2> RandomDevice::NextArrayVec2(AuUInt32 uCount, AuVec2 boundA, AuVec2 boundB)
|
|
|
|
{
|
|
|
|
AuVec2 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
return NextArrayVec2Sorted(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-24 13:33:06 +00:00
|
|
|
AuList<AuVec2> RandomDevice::NextArrayVec2Fast(AuUInt32 uCount, AuVec2 boundA, AuVec2 boundB)
|
|
|
|
{
|
|
|
|
AuVec2 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
return NextArrayVec2SortedFast(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuList<AuVec2> RandomDevice::NextArrayVec2Sorted(AuUInt32 uCount, AuVec2 min, AuVec2 max)
|
|
|
|
{
|
|
|
|
AuVec2 range;
|
|
|
|
AuList<AuVec2> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uSeed = rngBytes[uIndex];
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec2 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec2> RandomDevice::NextArrayVec2SortedFast(AuUInt32 uCount, AuVec2 min, AuVec2 max)
|
|
|
|
{
|
|
|
|
AuVec2 range;
|
|
|
|
AuList<AuVec2> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
|
|
|
|
AuUInt64 uSeed = this->NextU64();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec2 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec3> RandomDevice::NextArrayVec3(AuUInt32 uCount, AuVec3 boundA, AuVec3 boundB)
|
|
|
|
{
|
|
|
|
AuVec3 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
return NextArrayVec3Sorted(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-24 13:33:06 +00:00
|
|
|
AuList<AuVec3> RandomDevice::NextArrayVec3Fast(AuUInt32 uCount, AuVec3 boundA, AuVec3 boundB)
|
|
|
|
{
|
|
|
|
AuVec3 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
return NextArrayVec3SortedFast(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuList<AuVec3> RandomDevice::NextArrayVec3Sorted(AuUInt32 uCount, AuVec3 min, AuVec3 max)
|
|
|
|
{
|
|
|
|
AuVec3 range;
|
|
|
|
AuList<AuVec3> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uSeed = rngBytes[uIndex];
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec3 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec3> RandomDevice::NextArrayVec3SortedFast(AuUInt32 uCount, AuVec3 min, AuVec3 max)
|
|
|
|
{
|
|
|
|
AuVec3 range;
|
|
|
|
AuList<AuVec3> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
|
|
|
|
AuUInt64 uSeed = this->NextU64();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec3 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec4> RandomDevice::NextArrayVec4(AuUInt32 uCount, AuVec4 boundA, AuVec4 boundB)
|
|
|
|
{
|
|
|
|
AuVec4 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
mins[3] = AuMin(boundA[3], boundB[3]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
maxs[3] = AuMax(boundA[3], boundB[3]);
|
|
|
|
return NextArrayVec4Sorted(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-24 13:33:06 +00:00
|
|
|
AuList<AuVec4> RandomDevice::NextArrayVec4Fast(AuUInt32 uCount, AuVec4 boundA, AuVec4 boundB)
|
|
|
|
{
|
|
|
|
AuVec4 mins, maxs;
|
|
|
|
mins[0] = AuMin(boundA[0], boundB[0]);
|
|
|
|
mins[1] = AuMin(boundA[1], boundB[1]);
|
|
|
|
mins[2] = AuMin(boundA[2], boundB[2]);
|
|
|
|
mins[3] = AuMin(boundA[3], boundB[3]);
|
|
|
|
maxs[0] = AuMax(boundA[0], boundB[0]);
|
|
|
|
maxs[1] = AuMax(boundA[1], boundB[1]);
|
|
|
|
maxs[2] = AuMax(boundA[2], boundB[2]);
|
|
|
|
maxs[3] = AuMax(boundA[3], boundB[3]);
|
|
|
|
return NextArrayVec4SortedFast(uCount, mins, maxs);
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuList<AuVec4> RandomDevice::NextArrayVec4Sorted(AuUInt32 uCount, AuVec4 min, AuVec4 max)
|
|
|
|
{
|
|
|
|
AuVec4 range;
|
|
|
|
AuList<AuVec4> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
range[3] = max[3] - min[3];
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
auto uSeed = rngBytes[uIndex];
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed);
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentD = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec4 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2],
|
|
|
|
(dComponentD * range[3]) + min[3]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<AuVec4> RandomDevice::NextArrayVec4SortedFast(AuUInt32 uCount, AuVec4 min, AuVec4 max)
|
|
|
|
{
|
|
|
|
AuVec4 range;
|
|
|
|
AuList<AuVec4> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
range[0] = max[0] - min[0];
|
|
|
|
range[1] = max[1] - min[1];
|
|
|
|
range[2] = max[2] - min[2];
|
|
|
|
range[3] = max[3] - min[3];
|
|
|
|
|
|
|
|
AuUInt64 uSeed = this->NextU64();
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
2024-05-27 14:46:00 +00:00
|
|
|
auto dComponentA = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentB = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentC = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
|
|
|
auto dComponentD = RngConvertToDecimal(uSeed = (AuFnv1a64Runtime<8>(&uSeed)));
|
2024-04-22 05:02:56 +00:00
|
|
|
|
|
|
|
ret[uIndex] = AuVec4 {
|
2024-05-27 14:46:00 +00:00
|
|
|
(dComponentA * range[0]) + min[0],
|
|
|
|
(dComponentB * range[1]) + min[1],
|
|
|
|
(dComponentC * range[2]) + min[2],
|
|
|
|
(dComponentD * range[3]) + min[3]
|
2024-04-22 05:02:56 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-01-01 14:10:42 +00:00
|
|
|
AuList<double> RandomDevice::NextArrayDouble(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<double> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
this->Read(ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<double> RandomDevice::NextArrayDecimals(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
#if defined(AURNG_USE_FAST_DECIMALS)
|
|
|
|
AuList<double> ret;
|
|
|
|
AuList<AuUInt64> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, rngBytes.size()))
|
|
|
|
{
|
|
|
|
ret[uIndex] = RngConvertToDecimal(rngBytes[uIndex]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#else
|
|
|
|
AuList<double> ret;
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
ret[uIndex] = this->NextDecimal();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2023-12-01 03:04:26 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2024-04-22 05:02:56 +00:00
|
|
|
AuList<double> RandomDevice::NextArrayDecimalsFast(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<double> ret;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
|
|
|
|
AuUInt64 uSeed = this->NextU64();
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
ret[uIndex] = RngConvertToDecimal(uSeed);
|
2024-04-23 21:24:07 +00:00
|
|
|
uSeed = AuFnv1a64Runtime<8>(&uSeed);
|
2024-04-22 05:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
double RandomDevice::NextDecimal()
|
|
|
|
{
|
2024-01-01 14:10:42 +00:00
|
|
|
#if defined(AURNG_USE_FAST_DECIMALS)
|
|
|
|
return RngConvertToDecimal(this->NextU64());
|
|
|
|
#elif defined(AURNG_USE_UNIFORM_DECIMALS)
|
|
|
|
return this->UniformFloatInRange(kDblEpsilon, 1.0 + kDblEpsilon) - kDblEpsilon;
|
|
|
|
#elif defined(AURNG_USE_GARBAGE_DECIMALS)
|
|
|
|
return this->UniformFloatInRange(0, 1.0);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-17 07:46:07 +00:00
|
|
|
AuUInt32 RandomDevice::NextIndex(AuUInt32 uCount /* = max + 1*/)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-11-15 17:53:37 +00:00
|
|
|
auto uMassiveWord = NextU32();
|
2024-01-11 09:17:56 +00:00
|
|
|
auto uUpperBound = AuRoundUpPow2(uCount);
|
2023-11-15 17:53:37 +00:00
|
|
|
AuUInt32 uNext {};
|
|
|
|
while ((uNext = (uMassiveWord & (uUpperBound - 1))) >= uCount)
|
|
|
|
{
|
2024-04-23 21:24:07 +00:00
|
|
|
uMassiveWord = AuFnv1a32Runtime<sizeof(uMassiveWord)>(&uMassiveWord);
|
2023-11-15 17:53:37 +00:00
|
|
|
}
|
|
|
|
return uNext;
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2023-12-01 03:04:26 +00:00
|
|
|
|
|
|
|
double RandomDevice::NextNumber(double dMin, double dMax)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2023-12-01 03:17:56 +00:00
|
|
|
auto dRange = dMax - dMin;
|
2024-01-01 14:10:42 +00:00
|
|
|
#if defined(AURNG_USE_FAST_DECIMALS)
|
|
|
|
return (this->NextDecimal() * dRange) + dMin;
|
|
|
|
#else
|
|
|
|
// potentially not deterministic, thanks to runtime/platform deviations
|
2023-12-04 21:11:32 +00:00
|
|
|
return this->UniformFloatInRange(kDblEpsilon, dRange + kDblEpsilon) + dMin - kDblEpsilon;
|
2024-01-01 14:10:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
AuList<uuids::uuid> RandomDevice::NextArrayUUIDs(AuUInt32 uCount)
|
|
|
|
{
|
|
|
|
AuList<uuids::uuid> ret;
|
|
|
|
AuList<AuUInt8> rngBytes;
|
|
|
|
|
|
|
|
ret.resize(uCount);
|
|
|
|
rngBytes.resize(uCount * 16);
|
|
|
|
this->Read(rngBytes);
|
|
|
|
|
|
|
|
for (AU_ITERATE_N(uIndex, uCount))
|
|
|
|
{
|
|
|
|
auto pBytes = rngBytes.data() + (uIndex * 16);
|
|
|
|
|
|
|
|
pBytes[8] &= 0xBF;
|
|
|
|
pBytes[8] |= 0x80;
|
|
|
|
|
|
|
|
pBytes[6] &= 0x4F;
|
|
|
|
pBytes[6] |= 0x40;
|
|
|
|
|
|
|
|
ret[uIndex] = uuids::uuid { pBytes, pBytes + 16 };
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2022-12-28 20:07:41 +00:00
|
|
|
|
2023-12-29 22:57:25 +00:00
|
|
|
uuids::uuid RandomDevice::NextUUID()
|
|
|
|
{
|
|
|
|
AuUInt8 bytes[16];
|
|
|
|
this->Read(bytes);
|
|
|
|
|
|
|
|
bytes[8] &= 0xBF;
|
|
|
|
bytes[8] |= 0x80;
|
|
|
|
|
|
|
|
bytes[6] &= 0x4F;
|
|
|
|
bytes[6] |= 0x40;
|
|
|
|
|
|
|
|
return uuids::uuid { bytes, bytes + 16 };
|
|
|
|
}
|
|
|
|
|
2022-12-28 20:07:41 +00:00
|
|
|
AuMemoryViewRead RandomDevice::ToSeed()
|
|
|
|
{
|
|
|
|
if (this->def_.bSecure)
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->fast_.state;
|
|
|
|
}
|
|
|
|
|
2024-01-03 23:52:57 +00:00
|
|
|
IO::IStreamReader *RandomDevice::ToStreamReader()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
AUKN_SYM IRandomDevice *RandomNew(const Aurora::RNG::RandomDef &def)
|
|
|
|
{
|
2022-09-19 01:34:57 +00:00
|
|
|
auto pDevice = _new RandomDevice();
|
|
|
|
if (!pDevice)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2022-09-19 01:34:57 +00:00
|
|
|
pDevice->Init(def);
|
2021-09-06 10:58:08 +00:00
|
|
|
|
2022-09-19 01:34:57 +00:00
|
|
|
return pDevice;
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-28 20:07:41 +00:00
|
|
|
AUKN_SYM void RandomRelease(IRandomDevice *pDevice)
|
2021-09-06 10:58:08 +00:00
|
|
|
{
|
2022-12-28 20:07:41 +00:00
|
|
|
AuSafeDelete<RandomDevice *>(pDevice);
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|
2023-10-17 09:03:15 +00:00
|
|
|
|
|
|
|
AUROXTL_INTERFACE_SOO_SRC(Random, RandomDevice, (const RandomDef &, def))
|
2021-09-06 10:58:08 +00:00
|
|
|
}
|