PH Logo
Logo intepreter modeled after UCB Logo.
/Users/paul/Documents/phlogo/core/RandomVerbs.cpp
00001 /*
00002  *  PredicateVerbs.cpp
00003  *
00004  *  Author: Paul Hamilton
00005  *      Date: 17 Aug 2011
00006  *
00007  */
00008 
00009 #include "Verbs.h"
00010 
00011 #include "Thing.h"
00012 #include "World.h"
00013 #include "TokenStream.h"
00014 
00015 #include <math.h>
00016 
00017 using namespace std;
00018 using namespace boost;
00019 
00020 namespace phlogo {
00021     
00022 void Verbs::random(TokenStream *ts) {
00023 
00024     long low = getLong(ts);
00025     long high = 0;
00026         if (ts->withinSubExpression())
00027         high = getLong(ts);
00028         else {
00029         high = low;
00030         low = 0;
00031     }
00032     double n = (double)::rand()/(double)RAND_MAX;
00033     double x = (n * (high-low)) + low;
00034     setLongResult((long)x);
00035 }    
00036 
00037 void Verbs::rerandom(TokenStream *ts) {
00038     
00039     srand(getLong(ts));
00040 
00041 }
00042 
00043 }
 All Classes Functions