我必须在机器人框架中生成唯一的随机数.我使用生成随机字符串"来获取随机数.命令:
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])我在 for 循环中给出了上述语句.现在我能够得到'n'个随机数.但它们并不是独一无二的.我如何让它们独一无二?
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?
我的情况到底是什么:我想要四个唯一的随机数,范围从 1 到 10.我试图在 for 循环中给出生成随机数命令,在第二个循环中我试图将它与第一个随机值进行比较等等上.但这不起作用.
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.
有没有什么简单的逻辑可以得到 1 到 10 之间的 4 个唯一随机数?
Is there any simple logic to get 4 unique random numbers between 1 to 10?
提前致谢.
推荐答案我认为随机模块的 sample 函数是最优雅的解决方案.这里从 1 到 10 的一组数字中取出 4 个:
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更多推荐
Robot Framework:生成唯一随机数
发布评论