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
Verified
Serious PSXDEV User
Serious PSXDEV User
Posts: 124
Joined: Jan 07, 2018
I am a: Game Designer
PlayStation Model: SCPH-5502
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
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

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), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
NITROYUASH
Verified
Serious PSXDEV User
Serious PSXDEV User
Posts: 124
Joined: Jan 07, 2018
I am a: Game Designer
PlayStation Model: SCPH-5502
Location: Russian Federation
Contact:

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
Verified
Admin / PSXDEV
Admin / PSXDEV
Posts: 2670
Joined: Dec 31, 2012
PlayStation Model: H2000/5502
Discord: Shadow^PSXDEV

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), PSIO Switch Board, DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

PlayStation Development PC: Windows 98 SE, Pentium 3 at 400MHz, 128MB SDRAM, DTL-H2000, DTL-H2010, DTL-H201A, DTL-S2020 (with 4GB SCSI-2 HDD), 21" Sony G420, CD-R burner, 3.25" and 5.25" Floppy Diskette Drives, ZIP 100 Diskette Drive and an IBM Model M keyboard.

User avatar
NITROYUASH
Verified
Serious PSXDEV User
Serious PSXDEV User
Posts: 124
Joined: Jan 07, 2018
I am a: Game Designer
PlayStation Model: SCPH-5502
Location: Russian Federation
Contact:

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
Verified
C Programming Expert
C Programming Expert
Posts: 161
Joined: Oct 06, 2012
PlayStation Model: SCPH-5502
Contact:

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.

User avatar
MrQuetch
Active PSXDEV User
Active PSXDEV User
Posts: 42
Joined: Apr 01, 2018
I am a: Programmer and artist.
Motto: You can accomplish anything.
Location: United States

Post by MrQuetch » February 23rd, 2020, 1:31 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests