Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shuffle fixes/improvements #3128

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/random.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "global.h"
#include "random.h"
#if MODERN
#include <alloca.h>
#endif

EWRAM_DATA static u8 sUnknown = 0;
EWRAM_DATA static u32 sRandCount = 0;
Expand Down Expand Up @@ -37,7 +40,7 @@ u16 Random2(void)
--n; \
while (n > 1) \
{ \
int j = Random() % (n+1); \
int j = (Random() * (n+1)) >> 16; \
SWAP(data[n], data[j], tmp); \
--n; \
}
Expand Down Expand Up @@ -66,7 +69,7 @@ void ShuffleN(void *data, size_t n, size_t size)
--n;
while (n > 1)
{
int j = Random() % (n+1);
int j = (Random() * (n+1)) >> 16;
memcpy(tmp, (u8 *)data + n*size, size); // tmp = data[n];
memcpy((u8 *)data + n*size, (u8 *)data + j*size, size); // data[n] = data[j];
memcpy((u8 *)data + j*size, tmp, size); // data[j] = tmp;
Expand Down