I have to generate unique random numbers in robot framework. I have used \"Generate Random String\" to get random numbers. Command:
${random} Generate Ran
Generate 4 Random And Unique Numbers
${numbers} Create List 1 2 3 4 5
... 6 7 8 9 10
${random index} Generate Random String 1 0123456789
${random number 1} Set Variable @{numbers}[${random index}]
Remove From List ${numbers} ${random index}
${random index} Generate Random String 1 012345678
${random number 2} Set Variable @{numbers}[${random index}]
Remove From List ${numbers} ${random index}
${random index} Generate Random String 1 01234567
${random number 3} Set Variable @{numbers}[${random index}]
Remove From List ${numbers} ${random index}
${random index} Generate Random String 1 0123456
${random number 4} Set Variable @{numbers}[${random index}]
Remove From List ${numbers} ${random index}
${random numbers} Create List ${random number 1} ${random number 2} ${random number 3} ${random number 4}
[Return] ${random numbers}
or with python
import random
def generate_4_random_and_unique_numbers():
pool = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
random_numbers = []
for index in range (0, 4):
index = random.randint(0, len(pool)-1)
random_numbers.append(pool[index])
del pool[index]
return random_numbers
In general, create a list of possible numbers. Pick number randomly from that list and then delete that number from the list. Repeat as many times as needed.