-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.cc
72 lines (62 loc) · 1.15 KB
/
calc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
calc.cc
(c) Richard Thrippleton
Licensing terms are in the 'LICENSE' file
If that file is not included with this source then permission is not given to use this source in any way whatsoever.
*/
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "error.h"
#include "calc.h"
#include "os.h"
void calc::init()
{
for(int i=0;i<10;i++)
{
wrp[i]=i*i*i*100;
}
}
long calc::rnd(long max)
{
if(max==0)
return 0;
std::uniform_int_distribution<long> distribution(0, max);
return distribution(randomGenerator);
}
void calc::getspeed(long spd,char* put)
{
int j; //To extract the value from the loop
j=0;
for(int i=9;i>=0;i--)
{
if(spd>=wrp[i])
{
j=i;
break;
}
}
if(j==0)
if(spd<10)
sprintf(put,"0.0%ld c",spd);
else
sprintf(put,"0.%ld c",spd);
else
sprintf(put,"Warp %hd",j);
}
bool calc::dateq(unsigned char* d1,unsigned char* d2,int n)
{
for(int i=0;i<n;i++)
if(d1[i]!=d2[i])
return false;
return true;
}
void calc::obscure(char* str)
{
for(int i=0,j=strlen(str);i<j;i++)
str[i]+=i+1;
}
long calc::wrp[10];
char calc::spds[33];
std::mt19937 calc::randomGenerator(os::getseed());