home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
348.lha
/
chatterbox_v1.0
/
sources
/
rerandom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-14
|
2KB
|
65 lines
/* sound effect gimmick player - rerandomize routines to do random
* selection without replacement */
#include <exec/types.h>
#include <functions.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <stdio.h>
#include <fcntl.h>
#include "assert.h"
#include "iff.h"
#include "8svx.h"
#include "sample.h"
#include "chatter.h"
extern struct gab_info gab_data[N_GAB_TYPES];
/* rerandomize randomizes the sample play order for a given gab type
* It is called by Blather() and by startup code to randomize the
* list of sample pointers. By then walking through the list, and
* rerandomizing every time we finish playing all the samples in the
* list, we implement random selection without replacement reasonably
* efficiently.
*
* The reason we don't use pure random selection is that it is too
* annoying to get the same sample a whole bunch of times
*/
rerandomize(gab_type)
int gab_type;
{
register struct gab_info *gabp;
register int i, one_to_switch;
register Sample *samptemp;
gabp = &gab_data[gab_type];
gabp->next_play_gab_item = 0;
for (i = 0; i < gabp->n_gab_items; i++)
{
one_to_switch = rando(gabp->n_gab_items);
if (one_to_switch != i)
{
samptemp = gabp->Samples[i];
assert(samptemp && gabp->Samples[one_to_switch]);
gabp->Samples[i] = gabp->Samples[one_to_switch];
gabp->Samples[one_to_switch] = samptemp;
}
}
}
/* note: Config() must have been called, and all samples loaded, before
* calling randomize_all()
*/
randomize_all()
{
int gab_type;
for (gab_type = 0; gab_type < N_GAB_TYPES; gab_type++)
rerandomize(gab_type);
}