Annotation of parser3/src/classes/random.C, revision 1.3

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: 
1.3     ! paf         8:        $Id: random.C,v 1.2 2001/04/02 08:49:38 paf Exp $
1.1       paf         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;
1.2       paf        31:     if(max<=1)
1.3     ! paf        32:                PTHROW(0, 0,
1.2       paf        33:                        &method_name,
                     34:                        "bad range [0..%u]", max);
1.1       paf        35:        
                     36:        r.write_no_lang(*new(pool) VInt(pool, rand()%max));
                     37: }
                     38: 
                     39: // initialize
                     40: 
                     41: void initialize_random_class(Pool& pool, VStateless_class& vclass) {
                     42:        // setting seed
                     43:        srand(getpid()+time(NULL));  rand();
                     44:        
                     45:        // ^random.generate[]
                     46:        // ^random.generate(range)
                     47:        vclass.add_native_method("generate", Method::CT_STATIC, _generate, 0, 1);
                     48: }

E-mail: