Robot Framework: Generating Unique Random number

robotframework

I have to generate unique random numbers in robot framework. I have used "Generate Random String" to get random numbers. Command:

${random}   Generate Random String  1   [NUMBERS])

I gave the above statement in a for loop. Now I am able to get 'n' random numbers. But they are not unique. How do I make them unique?

Whats my case exactly: I want four unique random numbers ranging from 1 to 10. I am trying to give the generate random number command in for loop and in the second loop i am trying to compare it with first random value and so on. But this is not working.

Is there any simple logic to get 4 unique random numbers between 1 to 10?

Thanks in advance.

Best Solution

I think the random module's sample function is the most elegant solution. Here taking 4 out of the set of numbers from 1 to 10 inclusive:

${numbers}=    Evaluate    random.sample(range(1, 11), 4)    random

This returns a list of int's. If you want string representation of numbers...

${numbers}=    Evaluate    random.sample([unicode(x) for x in range(1, 11)], 4)    random
Related Question