Annotation of parser3/src/classes/random.C, revision 1.1
1.1 ! paf 1: /** @file
! 2: Parser: random parser class.
! 3:
! 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
! 5:
! 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
! 7:
! 8: $Id: random.C,v 1.41 2001/03/30 09:58:57 paf Exp $
! 9: */
! 10:
! 11: #include <process.h>
! 12: #include <time.h>
! 13:
! 14: #include "pa_config_includes.h"
! 15: #include "pa_common.h"
! 16: #include "_random.h"
! 17: #include "pa_vint.h"
! 18: #include "pa_request.h"
! 19:
! 20: // global var
! 21:
! 22: VStateless_class *random_class;
! 23:
! 24: // methods
! 25:
! 26: static void _generate(Request& r, const String& method_name, Array *params) {
! 27: Pool& pool=r.pool();
! 28:
! 29: uint max=params->size()?
! 30: (uint)(r.process(*static_cast<Value *>(params->get(0)))).as_double():0;
! 31: if(max<=0)
! 32: max=1000000;
! 33:
! 34: r.write_no_lang(*new(pool) VInt(pool, rand()%max));
! 35: }
! 36:
! 37: // initialize
! 38:
! 39: void initialize_random_class(Pool& pool, VStateless_class& vclass) {
! 40: // setting seed
! 41: srand(getpid()+time(NULL)); rand();
! 42:
! 43: // ^random.generate[]
! 44: // ^random.generate(range)
! 45: vclass.add_native_method("generate", Method::CT_STATIC, _generate, 0, 1);
! 46: }
E-mail: