From b5678d2feec83452973f40b3a16ac30c55d6f5a9 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 6 Jun 2018 03:28:16 +0200 Subject: add rand --- calc.y | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'calc.y') diff --git a/calc.y b/calc.y index e6bb2d9..3ca3083 100644 --- a/calc.y +++ b/calc.y @@ -3,7 +3,11 @@ package main -import "math" +import ( + "math" + "math/rand" + "time" +) var reg = map[string]float64{ "pi": math.Pi, @@ -46,6 +50,7 @@ exp : NUMBER | WORD { $$ = reg[$1] } | '_' { $$ = reg[last] } + | '!' { $$ = rand.Float64() } | exp '+' exp { $$ = $1 + $3 } | exp '-' exp { $$ = $1 - $3 } | exp '*' exp { $$ = $1 * $3 } @@ -59,6 +64,10 @@ exp %% +func init() { + rand.Seed(time.Now().UnixNano()) +} + func Parse(input string) (float64, bool, error) { l := lex(input) yyParse(l) -- cgit v1.2.3