-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomNumberGenerator.py
72 lines (62 loc) · 2.13 KB
/
randomNumberGenerator.py
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
#Code generated by Tomás Araújo
#10-05-2022
#Imports
import random as rand
from configparser import ConfigParser
import os
from os.path import exists
#Reading Limits
#Rev
def revRandomNumberGenerator():
#READ LIMITS CONFIG.INI
config = ConfigParser()
config.read('config.ini')
valuesRev = [] #This is a blank list variable in which I append an array(s)
#DEFINE MINIMUM AND MAXIMUM
minRev= int(config['rev']['minRev'])
maxRev= int(config['rev']['maxRev'])
minTimeOnR= int(config['rev']['minTimeOn'])
maxTimeOnR= int(config['rev']['maxTimeOn'])
minTimeChangeR= int(config['rev']['minTimeChange'])
maxTimeChangeR= int(config['rev']['maxTimeChange'])
#RANDOM NUMBER GENERATOR
rng1 = rand.randint(minRev,maxRev)
rng2 = rand.randint(minTimeOnR,maxTimeOnR)
rng3 = rand.randint(minTimeChangeR,maxTimeChangeR)
#APPEND VALUES TO ARRAY
valuesRev.append((rng1,rng2,rng3))
valuesRev2=(rng1,rng2,rng3)
str1=[str(rng1),str(rng2),str(rng3)]
strRev = ','.join(str1)
with open('valuesRev.txt', 'a') as f:
f.write(strRev)
f.write("\n")
return rng1,rng2,rng3
#Valve
def valveNumberGenerator():
config = ConfigParser()
config.read('config.ini')
valuesValve = []
minValve= int(config['valve']['minValve'])
maxValve= int(config['valve']['maxValve'])
minTimeOnV = int(config['valve']['minTimeOn'])
maxTimeOnV = int(config['valve']['maxTimeOn'])
minTimeChangeV = int(config['valve']['minTimeChange'])
maxTimeChangeV = int(config['valve']['maxTimeChange'])
rng4 = rand.randint(minValve,maxValve)
rng5 = rand.randint(minTimeOnV,maxTimeOnV)
rng6 = rand.randint(minTimeChangeV,maxTimeChangeV)
valuesValve.append((rng4,rng5,rng6))
str2=[str(rng4),str(rng5),str(rng6)]
strValve = ','.join(str2)
with open('valuesValve.txt', 'a') as v:
v.write(strValve)
v.write("\n")
return rng4,rng5,rng6
def deleteFiles():
file_exists = exists("valuesValve.txt")
file_exists2 = exists("valuesRev.txt")
if(file_exists):
os.remove("valuesValve.txt")
if(file_exists2):
os.remove("valuesRev.txt")