qnetdice

view src/roll.cc @ 4:7d28bef3fbca

ops, forgot to add +1 to random numbers in roll.cc to make them 1-based
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Dec 2013 17:40:34 +0200
parents 92377189a5c6
children
line source
1 #include <stdlib.h>
2 #include <math.h>
3 #include "roll.h"
5 Roll::Roll(int sides)
6 {
7 this->sides = sides;
8 value = 0;
9 }
11 void Roll::set_name(const char *name)
12 {
13 this->name = std::string(name);
14 }
16 void Roll::set_sides(int sides)
17 {
18 this->sides = sides;
19 }
21 void Roll::set_value(int value)
22 {
23 this->value = value;
24 }
26 const char *Roll::get_name() const
27 {
28 return name.c_str();
29 }
31 int Roll::get_sides() const
32 {
33 return sides;
34 }
36 int Roll::get_value() const
37 {
38 return value;
39 }
41 int Roll::roll()
42 {
43 value = (int)floor((double)sides * (double)rand() / (double)RAND_MAX) + 1;
44 return value;
45 }