//
// GameToolbox::gen_random from 0x581c68 to 0x581e50 (488 bytes)
//
// 2 xrefs:
// > GJMultiplayerManager::uploadComment @ 0x983ad8
// > ??> @ 0x8d138
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __usercall GameToolbox::gen_random@(GameToolbox *this@, __int64 a2@)
{
int v2; // w23
int i; // w21
int v5; // w0
char *v6; // x3
__int64 v7; // x2
__int64 v8; // x20
char v9; // w28
char *v10; // x0
char *v11; // x19
unsigned int *v13; // x1
int v14; // w0
char *v15; // [xsp+70h] [xbp+70h] BYREF
v2 = (int)this;
sub_D153B8((int)&v15, &byte_F288A0);
if ( v2 > 0 )
{
for ( i = 0; i != v2; ++i )
{
while ( 1 )
{
v5 = rand();
v6 = v15;
v7 = *((_QWORD *)v15 - 3);
v8 = v7 + 1;
v9 = a0123456789abcd_1[v5 % 0x3EuLL];
if ( (unsigned __int64)(v7 + 1) > *((_QWORD *)v15 - 2) || *((int *)v15 - 2) > 0 )
{
sub_D15888(&v15, v7 + 1);
v6 = v15;
v7 = *((_QWORD *)v15 - 3);
}
v6[v7] = v9;
v10 = v15;
if ( v15 - 24 != (char *)&qword_124B6B0 )
break;
if ( ++i == v2 )
goto LABEL_9;
}
*((_DWORD *)v15 - 2) = 0;
*((_QWORD *)v10 - 3) = v8;
v10[v8] = 0;
}
}
LABEL_9:
sub_D153B8(a2, v15);
v11 = v15 - 24;
if ( v15 - 24 != (char *)&qword_124B6B0 )
{
if ( &pthread_create )
{
v13 = (unsigned int *)(v15 - 8);
do
v14 = __ldaxr(v13);
while ( __stlxr(v14 - 1, v13) );
}
else
{
v14 = *((_DWORD *)v15 - 2);
*((_DWORD *)v15 - 2) = v14 - 1;
}
if ( v14 <= 0 )
operator delete(v11);
}
return a2;
}