Chris Browne cbbrowne at lists.slony.info
Wed Jun 6 15:20:41 PDT 2007
Update of /home/cvsd/slony1/slony1-engine/tests
In directory main.slony.info:/tmp/cvs-serv5846

Modified Files:
	support_funcs.sh 
Added Files:
	Makefile random_number.c random_string.c 
Log Message:
Add in C programs to more efficiently generate random numbers and strings
for generating random transactions


Index: support_funcs.sh
===================================================================
RCS file: /home/cvsd/slony1/slony1-engine/tests/support_funcs.sh,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** support_funcs.sh	21 Mar 2006 22:36:05 -0000	1.4
--- support_funcs.sh	6 Jun 2007 22:20:39 -0000	1.5
***************
*** 88,91 ****
--- 88,94 ----
    _upperbound=$2
  
+   if [ -e ./random_number ] ; then
+     rannum=`./random_number ${_lowerbound} ${_upperbound}`
+   else
    case `uname` in
    *BSD|Darwin)
***************
*** 113,116 ****
--- 116,120 ----
    ;;
    esac
+   fi
    echo ${rannum}
  }
***************
*** 123,126 ****
--- 127,133 ----
  
    _length=$1
+   if [ -e ./random_string ] ; then
+     rannum=`./random_string ${_length}`
+   else
    case `uname` in
    *BSD|Darwin)
***************
*** 151,155 ****
    ;;
    esac
! 
    echo ${ranstring}
  }
--- 158,162 ----
    ;;
    esac
!   fi
    echo ${ranstring}
  }

--- NEW FILE: random_string.c ---
/* $Id: random_string.c,v 1.2 2007-06-06 22:20:39 cbbrowne Exp $ */

#include <stdlib.h>
#include <stdio.h>

int main(int argc, const char *argv[])
{
	int length, i;
	int base, result;
	if (argc != 2) {
		printf("args: %d - random_string: length\n", argc);
		exit (1);
	}
	sscanf(argv[1], "%d", &length);

	srand(time(0));
	for (i = 0; i< length; i++) 
		printf("%c", (rand() % (122-48))+48);
	printf("\n", result);
}

--- NEW FILE: Makefile ---
all: random_number random_string

random_number: random_number.c
	$(CC) random_number.c -o random_number

random_string: random_string.c
	$(CC) random_string.c -o random_string
--- NEW FILE: random_number.c ---
/* $Id: random_number.c,v 1.2 2007-06-06 22:20:39 cbbrowne Exp $ */

#include <stdlib.h>
#include <stdio.h>

int main(int argc, const char *argv[])
{
	int lower, upper;
	int base, result;
	if (argc != 3) {
		printf("args: %d - random_number: lower_limit upper_limit\n", argc);
		exit (1);
	}
	sscanf(argv[1], "%d", &lower);
	sscanf(argv[2], "%d", &upper);

	srand(time(0));
	base = rand();
	result = (base % (upper - lower)) + lower;

	printf("%d\n", result);
}



More information about the Slony1-commit mailing list