Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improving generated random numbers
05-19-2013, 10:38 AM (This post was last modified: 05-19-2013 10:47 AM by 240-185.)
Post: #1
Improving generated random numbers
Hi,

I'm coding for now a homebrew which involves lots of random events, so I have to generate a lot of pseudo-random numbers. After having read tutorials from some places over the web, the code is:

Code:
int main(void)
{

SceKernelUtilsMt19937Context ctx;
sceKernelUtilsMt19937Init(&ctx, time(NULL));
char UnsecureBuffer[25];

u32 rand_val = (sceKernelUtilsMt19937UInt(&ctx))%201;
sprintf(UnsecureBuffer, "Your current IQ is: %d\n", (int)rand_val);

printf(UnsecureBuffer);

return 0;

}

This works on the real hardware, not in PPSSPP, where the generated number is always 0.
Find all posts by this user
Quote this message in a reply
05-19-2013, 03:51 PM
Post: #2
RE: Improving generated random numbers
Ah, we haven't implemented those functions yet. Presumably it's a Mersenne Twister MT19937 implementation. Pull request welcome.

I think the VFPU also provides random numbers (using rnds and e.g. rndi), but I don't know their quality.

-[Unknown]
Find all posts by this user
Quote this message in a reply
05-20-2013, 05:58 AM (This post was last modified: 05-20-2013 05:59 AM by Henrik.)
Post: #3
RE: Improving generated random numbers
Just for the record, I went ahead and implemented this. Haven't tested it yet though, please report if it works.

I don't know what generator the VFPU uses, but its state is "just" 8 32-bit registers IIRC so it can't be MT.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: