primo commit

This commit is contained in:
six 2023-02-28 22:16:34 +01:00
parent f4a6d7ef18
commit 5199e34a86

56
channel.frequency.gen.py Executable file
View file

@ -0,0 +1,56 @@
#!/bin/python3
import sys
import random
def channelFrequencyGenerator(lower_frequency, upper_frequency):
system_random = random.SystemRandom()
return system_random.uniform(lower_frequency, upper_frequency)
def isfloat(num):
try:
float(num)
return True
except ValueError:
return False
def isint(num):
try:
int(num)
return True
except ValueError:
return False
def valid(argv):
return (isfloat(argv[1]) and isfloat(argv[2]) and isfloat(argv[4]) and isint(argv[3]))
def verifyChannelSpacing(newchannel, channellist, spacing):
for channel in channellist:
if(newchannel - channel < spacing and channel - newchannel < spacing):
return False
else:
return True
def createChannelList(argv):
channellist= []
channellist.append(round(channelFrequencyGenerator(float(argv[1]), float(argv[2])), 5))
i = 1
j = 0
while i < int(argv[3]):
newchannel=round(channelFrequencyGenerator(float(argv[1]), float(argv[2])), 5)
if(verifyChannelSpacing(newchannel, channellist, float(argv[4]))):
channellist.append(newchannel)
i+=1
else:
j+=1
if j > 3 :
return channellist
return channellist
if __name__ == '__main__':
if (valid(sys.argv)):
print(createChannelList(sys.argv))
else:
print("invalid arguments")