Page 1 of 1
RAND and SRAND?
Posted: March 17th, 2018, 12:07 am
by NITROYUASH
Hello PSXDEV.
It is possible to make full random num. generator using something like that?
srand(time(NULL));
Found RAND/SRAND in C:/Psyq/include/RAND.H
I am not sure about "time()" in PS1...
Thanks c:
Re: RAND and SRAND?
Posted: March 17th, 2018, 2:46 am
by Shadow
Yes, use random with the root counter.
Re: RAND and SRAND?
Posted: March 17th, 2018, 3:16 am
by NITROYUASH
Huh, something like that?
SetRCnt(RCntCNT3,0,RCntMdNOINTR);
RandomTimer = (GetRCnt(RCntCNT3));
srand(RandomTimer);
Random = (rand() % 8);
Re: RAND and SRAND?
Posted: March 17th, 2018, 4:13 am
by Shadow
Code: Select all
///////////////////////////////////////////////////////////
// Random Number Generator
// --------------------------------------------------------
// returns a random number that does
// not exceed the maximum parsed value
// --------------------------------------------------------
// EG: Random(5) will return either 0,1,2,3 or 4
///////////////////////////////////////////////////////////
int Random(int max)
{
srand(GetRCnt(0)); // initialise the random seed generator
return(rand()%max); // return a random number based off of max
}
Re: RAND and SRAND?
Posted: March 17th, 2018, 4:32 am
by NITROYUASH
It's working. Thanks c:
Code: Select all
int SetRandomNUM(int maxnum) {
srand(GetRCnt(0));
RNum = (rand() % maxnum);
return RNum;
}
Re: RAND and SRAND?
Posted: March 20th, 2018, 10:57 pm
by Xavi92
I'm using another methode which measures how many VBlank interrupts have occurred until the player presses a button.
Re: RAND and SRAND?
Posted: February 23rd, 2020, 1:31 pm
by MrQuetch
This is really late. But, I just recently found the 'GsGetVcount' function. That may be helpful in getting a completely random number - besides the other methods already mentioned here. The vertical retraces happen really fast, so it seems reasonable.