RAND and SRAND?

General Programming help in C, C++ or ASM, Compiling / Debugging, and R3000A Central Processing Unit (CPU) information
Post Reply
User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 91
Joined: January 7th, 2018, 12:03 am
PlayStation Model: SCPH-5502
Steam: NITROYUASH
Location: Russian Federation
Contact:

RAND and SRAND?

Post by NITROYUASH » March 17th, 2018, 12:07 am

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:

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2251
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: RAND and SRAND?

Post by Shadow » March 17th, 2018, 2:46 am

Yes, use random with the root counter.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 91
Joined: January 7th, 2018, 12:03 am
PlayStation Model: SCPH-5502
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: RAND and SRAND?

Post by NITROYUASH » March 17th, 2018, 3:16 am

Huh, something like that?
SetRCnt(RCntCNT3,0,RCntMdNOINTR);
RandomTimer = (GetRCnt(RCntCNT3));
srand(RandomTimer);
Random = (rand() % 8);

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2251
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: RAND and SRAND?

Post by Shadow » March 17th, 2018, 4:13 am

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
}
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

User avatar
NITROYUASH
Serious PSXDEV User
Serious PSXDEV User
Posts: 91
Joined: January 7th, 2018, 12:03 am
PlayStation Model: SCPH-5502
Steam: NITROYUASH
Location: Russian Federation
Contact:

Re: RAND and SRAND?

Post by NITROYUASH » March 17th, 2018, 4:32 am

It's working. Thanks c:

Code: Select all

int SetRandomNUM(int maxnum) {
	srand(GetRCnt(0));
	RNum = (rand() % maxnum);

	return RNum;
}

Xavi92
C Programming Expert
C Programming Expert
Posts: 122
Joined: October 6th, 2012, 12:53 am

Re: RAND and SRAND?

Post by Xavi92 » March 20th, 2018, 10:57 pm

I'm using another methode which measures how many VBlank interrupts have occurred until the player presses a button.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest