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: 121
Joined: January 7th, 2018, 12:03 am
I am a: Game Designer
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: 2380
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), 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
Serious PSXDEV User
Serious PSXDEV User
Posts: 121
Joined: January 7th, 2018, 12:03 am
I am a: Game Designer
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: 2380
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), 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
Serious PSXDEV User
Serious PSXDEV User
Posts: 121
Joined: January 7th, 2018, 12:03 am
I am a: Game Designer
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: 127
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.

User avatar
MrQuetch
Active PSXDEV User
Active PSXDEV User
Posts: 40
Joined: April 1st, 2018, 9:34 am
I am a: Programmer and artist.
Motto: You can accomplish anything.
Want to Find: Saving and loading data.
Looking to: Create professional homebrew.
Location: United States

Re: RAND and SRAND?

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 1 guest