//
// GameToolbox::gen_random from 0x140070980 to 0x140070ace (334 bytes)
//
// 11 xrefs:
// > GameLevelManager::createNewLevel @ 0x14021c117
// > sub_140222BE0 @ 0x140222c34
// > GameLevelManager::writePlatformerSaveJournal @ 0x1402234f4
// > GameLevelManager::replayPlatformerSaveJournal @ 0x1402239a1
// > GJGameLevel::dataLoaded @ 0x140268eb6
// > GJGameLevel::encodeWithCoder @ 0x14026a4c8
// > GJMultiplayerManager::uploadComment @ 0x1403913b5
// > LevelEditorLayer::doAutoSave @ 0x1404092fb
// > LevelEditorLayer::doAutoBackup @ 0x14040984d
// > LocalLevelManager::tryRecoverAutoSaves @ 0x14046d588
// > ??> @ 0x140911804
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:25:49 +0000
//
// Hidden C++ exception states: #wind=2
void **__fastcall GameToolbox::gen_random(void **Src, unsigned int a2)
{
__int64 v2; // rdi
unsigned int v4; // eax
unsigned __int64 i; // r8
unsigned __int64 v6; // rdx
v2 = a2;
if ( dword_14090C0CC > *(_DWORD *)(*(_QWORD *)NtCurrentTeb()->ThreadLocalStoragePointer + 4LL) )
{
sub_140677B5C(&dword_14090C0CC);
if ( dword_14090C0CC == -1 )
{
v4 = std::_Random_device();
dword_14090D454 = -1;
dword_14090C0D4 = v4;
for ( i = 1; i < 0x270; ++i )
{
v4 = i + 1812433253 * (v4 ^ (v4 >> 30));
dword_14090C0D0[i + 1] = v4;
}
dword_14090C0D0[0] = 624;
Init_thread_footer(&dword_14090C0CC);
}
}
*(_OWORD *)Src = 0;
Src[2] = nullptr;
Src[3] = (void *)15;
*(_BYTE *)Src = 0;
sub_140059AB0(Src, (int)v2);
if ( (int)v2 > 0 )
{
do
{
v6 = 62LL * (unsigned int)sub_1400768C0(dword_14090C0D0);
if ( (unsigned int)v6 <= 3 )
{
do
v6 = 62LL * (unsigned int)sub_1400768C0(dword_14090C0D0);
while ( (unsigned int)v6 < 4 );
}
sub_14003DBD0(Src, a0123456789abcd[(HIDWORD(v6) - 0x80000000) ^ 0xFFFFFFFF80000000uLL]);
--v2;
}
while ( v2 );
}
return Src;
}