diff --git a/channel.frequency.gen.py b/channel.frequency.gen.py new file mode 100755 index 0000000..510642f --- /dev/null +++ b/channel.frequency.gen.py @@ -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") +