Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bezzant

Question Or Two

This topic is 6483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m making a game and want to add sound effects I have read everywhere that I will be needing the FMOD library etc... Well I have all those but can do nothing with them! Does any of you have some source code which loads a *.wav and/or *.mp3 files. Also does any of you know how to generate a random number in C++, the reason being, for my game I want power-ups to pop-up every now and then and I need to generate random positions for them. Many Thanks Alan IF YA SMELL... WHAT THE BEZZ IS COOKIN''''

Share this post


Link to post
Share on other sites
Advertisement
Cant answer the FMOD thing but this is the C library function for generating a random number:

int rand( void );

And the funtion to seed the generator is this

void srand( unsigned int seed );


This little lot was copied from the MSDN

The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

rand returns a pseudorandom number, as described above. There is no error return.

Remarks

The rand function returns a pseudorandom integer in the range 0 to RAND_MAX. Use the srand function to seed the pseudorandom-number generator before calling rand.

Example

/* RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
*/

#include
#include
#include

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!