forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

rand() function in Kernel Mode [RESOLVED]

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ADePSP



Joined: 13 Jul 2006
Posts: 58

PostPosted: Thu Sep 21, 2006 9:27 pm    Post subject: rand() function in Kernel Mode [RESOLVED] Reply with quote

I'm current trying to capture the PSP_CTRL_NOTE button but have found I need to run in Kernel Mode to get it... All my code compiles as before (after a few changes) apart from it doesn't recognise the rand() function anymore...

Anybody know a way to get around this...?

I tried to make my own rand() function like this but had no luck because now it doesn't recognise the time() function,

Code:

SceKernelUtilsMt19937Context ctx;

int RandomInit(void) {
  sceKernelUtilsMt19937Init(&ctx, time(NULL));
  return 0;
}

int get_random(int lo, int hi) {
  u32 rand_val = sceKernelUtilsMt19937UInt(&ctx);
  rand_val = lo + rand_val % (hi+1);
  return (int)rand_val;
}

int rand(void) {
  return get_random(0,RAND_MAX);
}


EDIT: I managed to get it working by declaring time as t_time in the RandomInit() function...

Thanks anyway...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group