From 0425aadc78680e53000fd0108b540d6eca048516 Mon Sep 17 00:00:00 2001 From: gmcdonald Date: Sat, 13 Feb 2010 01:32:03 +0000 Subject: Moving axis svn, part of TLP move INFRA-2441 git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68 --- util/src/rand.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 util/src/rand.c (limited to 'util/src/rand.c') diff --git a/util/src/rand.c b/util/src/rand.c new file mode 100644 index 0000000..c3a7aa9 --- /dev/null +++ b/util/src/rand.c @@ -0,0 +1,66 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#define AXIS2_RAND_MAX 32768 + +AXIS2_EXTERN int AXIS2_CALL +axutil_rand( + unsigned int *seedp) +{ + *seedp = *seedp * 1103515245 + 12345; + return ((unsigned)(*seedp / (2 * AXIS2_RAND_MAX)) % AXIS2_RAND_MAX); +} + +AXIS2_EXTERN int AXIS2_CALL +axutil_rand_with_range( + unsigned int *seedp, + int start, + int end) +{ + int rand = -1; + float range = 0.0; + if(start < 0 || end <= 0) + return -1; + if(start >= AXIS2_RAND_MAX || end > AXIS2_RAND_MAX) + return -1; + if(end <= start) + return -1; + + range = (float)(end - start); + rand = axutil_rand(seedp); + rand = start + (int)(range * rand / (AXIS2_RAND_MAX + 1.0)); + return rand; +} + +AXIS2_EXTERN unsigned int AXIS2_CALL +axutil_rand_get_seed_value_based_on_time( + const axutil_env_t * env) +{ + axutil_date_time_t *date = axutil_date_time_create(env); + unsigned int rand_var = axutil_date_time_get_year(date, env); + rand_var += axutil_date_time_get_month(date, env); + rand_var += axutil_date_time_get_date(date, env); + rand_var += axutil_date_time_get_hour(date, env); + rand_var += axutil_date_time_get_minute(date, env); + rand_var += axutil_date_time_get_second(date, env); + axutil_date_time_free(date, env); + return rand_var; +} -- cgit v1.1-32-gdbae