I have two files:

sort_comparison .c++

my_sort.h

sort_comparison .c++ calls this code in my_sort.h:

void my_sort::fillAr ray(int arr[],int n)

{

// const int random_number_r ange=1000000;

const int random_number_r ange=100;

int number,xcell;

randomNumber rnd;

for (xcell=0;xcell< n;xcell++)

{

number=rnd.rand om(random_numbe r_range);

arr[xcell]=rnd.random(num ber);

// arr[xcell]=rand();

}

}

The problem is that every array gets filled with the exact same data...

If I comment out:

number=rnd.rand om(random_numbe r_range);

arr[xcell]=rnd.random(num ber);

and replace it with

arr[xcell]=rand();

I get random data in my arrays... The complete code for both files is

below. Can anyone tell me why

number=rnd.rand om(random_numbe r_range);

arr[xcell]=rnd.random(num ber);

doesn't generate randomized data like "arr[xcell]=rand();"? Thanks.

////////////////////////////////////////////////////////////////////

//begin sort_comparison .c++

#include <ctime>

#include <iostream>

#include <string>

#include "../ftsoftds/include/d_random.h"

#include "../ftsoftds/include/d_sort.h" // Contains

selectionSort

//#include "../ftsoftds/include/d_timer.h"

#include "my_sort.h" // My sorting library.

using namespace std;

void printArray(stri ng name,int arr[],int n)

{

int cell;

cout<<name<<" Sort Array..."<<endl ;

for(cell=0;cell <n;cell++)

{

printf("%d ",arr[cell]);

}

cout<<endl;

}

////////////////////////////////////////////////////////////////////////////////

int main ()

{

// Declare five (5) integer arrays. Final array_size is 10,000 (ten

thousand).

const int array_size=25;

const int xrandom_number_ range=100;

int

array_selection _sort[array_size],array_insertio n_sort[array_size],

array_bubble_so rt[array_size],array_exchange _sort[array_size],

array_shell_sor t[array_size];

// Declare my_sort.h object (Did I reference this comment

correctly?).

my_sort my;

int cell,xnumber;

randomNumber xrnd;

/*

for(cell=0;cell <array_size;cel l++)

{

xnumber=xrnd.ra ndom(xrandom_nu mber_range);

array_selection _sort[cell]=xnumber;

}

for(cell=0;cell <array_size;cel l++)

{

printf("%d ",array_selecti on_sort[cell]);

}

cout<<endl;

for(cell=0;cell <array_size;cel l++)

{

xnumber=xrnd.ra ndom(xrandom_nu mber_range);

array_insertion _sort[cell]=xnumber;

}

for(cell=0;cell <array_size;cel l++)

{

printf("%d ",array_inserti on_sort[cell]);

}

cout<<endl;

for(cell=0;cell <array_size;cel l++)

{

array_exchange_ sort[cell]=4;

}

for(cell=0;cell <array_size;cel l++)

{

printf("%d ",array_exchang e_sort[cell]);

}

cout<<endl;

*/

my.fillArray(ar ray_selection_s ort,array_size) ;

my.fillArray(ar ray_insertion_s ort,array_size) ;

my.fillArray(ar ray_bubble_sort ,array_size);

my.fillArray(ar ray_exchange_so rt,array_size);

my.fillArray(ar ray_shell_sort, array_size);

// array_exchange_ sort[0]=99;

selectionSort(a rray_selection_ sort,array_size );

insertionSort(a rray_insertion_ sort,array_size );

// The following is used to verify that the arrays contain like data...

printArray("Sel ection",array_s election_sort,a rray_size);

printArray("Ins ertion",array_i nsertion_sort,a rray_size);

printArray("Bub ble",array_bubb le_sort,array_s ize);

printArray("Exc hange",array_ex change_sort,arr ay_size);

printArray("She ll",array_shell _sort,array_siz e);

return 0;

}

//end sort_comparison .c++

///////////////////////////////////////////////////////////////////////

//begin my_sort.h

class my_sort

{

int x, y;

public:

void bubbleSort(int arr[],int n);

void fillArray(int arr[],int n);

};

void my_sort::bubble Sort(int arr[],int n)

{

int i,j;

for(i = 0; i < n; i++)

for(j = i+1; j < n; j++)

if (arr[i] > arr[j]) { // swap arr[i] and arr[j]

int tmp = arr[i];

arr[i] = arr[j];

arr[j] = tmp;

}

}

////////////////////////////////////////////////////////////////////////////////

void my_sort::fillAr ray(int arr[],int n)

{

// const int random_number_r ange=1000000;

const int random_number_r ange=100;

int number,xcell;

randomNumber rnd;

for (xcell=0;xcell< n;xcell++)

{

number=rnd.rand om(random_numbe r_range);

arr[xcell]=rnd.random(num ber);

// arr[xcell]=rand();

}

}

//end my_sort.h