Date: 08/26/98
- Next message: zeev: "[PHP-DEV] CVS update: php3"
- Previous message: Bug Database: "[PHP-DEV] Bug #696 Updated: Wariables: HTTP_GET_VARS and HTTP_POST_VARS arent generated correct at frames"
- Next in thread: rasmus: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wednesday August 26, 1998 @ 15:44
Author: zeev
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv12971/functions
Modified Files:
rand.c
Log Message:
Add range support for rand()
Index: php3/functions/rand.c
diff -c php3/functions/rand.c:1.25 php3/functions/rand.c:1.26
*** php3/functions/rand.c:1.25 Fri May 15 06:57:36 1998
--- php3/functions/rand.c Wed Aug 26 15:44:42 1998
***************
*** 24,32 ****
| contact core <email protected> |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus <email protected>> |
+----------------------------------------------------------------------+
*/
! /* $Id: rand.c,v 1.25 1998/05/15 10:57:36 zeev Exp $ */
#include <stdlib.h>
--- 24,33 ----
| contact core <email protected> |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus <email protected>> |
+ | Zeev Suraski <bourbon <email protected> |
+----------------------------------------------------------------------+
*/
! /* $Id: rand.c,v 1.26 1998/08/26 19:44:42 zeev Exp $ */
#include <stdlib.h>
***************
*** 59,64 ****
--- 60,85 ----
void php3_rand(INTERNAL_FUNCTION_PARAMETERS)
{
+ pval *p_min=NULL, *p_max=NULL;
+
+ switch (ARG_COUNT(ht)) {
+ case 0:
+ break;
+ case 2:
+ if (getParameters(ht, 2, &p_min, &p_max)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_long(p_min);
+ convert_to_long(p_max);
+ if (p_max->value.lval-p_min->value.lval <= 0) {
+ php3_error(E_WARNING,"rand(): Invalid range: %ld..%ld", p_min->value.lval, p_max->value.lval);
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+
return_value->type = IS_LONG;
#ifdef HAVE_LRAND48
return_value->value.lval = lrand48();
***************
*** 69,74 ****
--- 90,99 ----
return_value->value.lval = rand();
#endif
#endif
+
+ if (p_min && p_max) { /* implement range */
+ return_value->value.lval = (return_value->value.lval%(p_max->value.lval-p_min->value.lval+1))+p_min->value.lval;
+ }
}
void php3_getrandmax(INTERNAL_FUNCTION_PARAMETERS)
-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>
- Next message: zeev: "[PHP-DEV] CVS update: php3"
- Previous message: Bug Database: "[PHP-DEV] Bug #696 Updated: Wariables: HTTP_GET_VARS and HTTP_POST_VARS arent generated correct at frames"
- Next in thread: rasmus: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

