gen_data(), show_data(), OK 
(高顯忠, sjgau4311@gmail.com, 2010-12-23 12:37)    
                        1樓
                        
                        #include <cstdlib>
#include <iostream>
// --------------------------------------------------------
#include <time.h>
// --------------------------------------------------------
using namespace std;
// --------------------------------------------------------
//   swap_int(&i1, &i2);
void swap_int(int *a, int *b)
{
	int c;
	c= (*a);
	(*a)= (*b);
	(*b)= c;
}// end of swap_int()
// --------------------------------------------------------
//   gen_data(a, n, 10, 99, 123);
void gen_data(int a[], int n, int i1, int i2, int ctrl_code)
{
	int i;
	// set i1 <= i2
	if (i1 > i2) {
		swap_int(&i1, &i2);
	}
	if (ctrl_code <= 0) {// set srand()
		srand((unsigned) time(NULL));
	}
	else {// used the ctrl_code to seed
		srand(ctrl_code);
	}
	for (i=0;i<n;i++) {
		a[i]= (rand()%(i2 - i1 + 1)) + i1;
	}
}// end of gen_data()
// --------------------------------------------------------
//   show_data(a, n);
void show_data(int a[], int n)
{
	int i;
	printf("\n");
	for (i=0;i<n;i++) {
		printf("%3d, ", a[i]);
	}
	printf("\n");
	system("pause");
}// end of show_data()
// --------------------------------------------------------
int main(int argc, char *argv[])
{
    //
	int a[1024], n, i1, i2, ctrl_code;// 1K * 4 Bytes, --> 4K
	n= 15;
	i1= 6; 
	i2= 1;
	ctrl_code= -123;
	gen_data(a, n, i1, i2, ctrl_code);
	show_data(a, n);
	// bubble_sort(a, n);
	// check_data(a, n);
    // system("PAUSE");
    return EXIT_SUCCESS;
}// end of main()
// ----------------------------------------------

 
        

