1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/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")
|