有人知道如何在Katalon中生成随机的2个十进制浮点数吗?
我已经尝试过此代码,但是它不起作用。
import java.util.Random as Random
float randFloat(float min, floatmax) {
Random rand = new Random()
float result = (rand.nextFloat() * (max - min)) + min
return result
}
答案 0 :(得分:1)
如果您从代码中复制代码,则在函数参数中出现错字应该是:
int pop(stack *p);
int main(int argc, char **argv)
{
stack ph;
int i, a, b;
int val = 0;
if (argc!=2)
{
printf("Usage: %s argument\n", argv[0]);
exit(1);
}
else{
int i;
int length = strlen(argv[1]);
int count;
initializedStack(&ph);
for(i=0;i<length;i++)
{
if (argv[1][i] == '+'){
a = pop(&ph);
printf("%d\n", a);
b = pop(&ph);
printf("%d\n", b);
val = a+b;
push(&ph,val);
}
else{
push(&ph, argv[1][i]);
}
}
printf("%d\n", pop(&ph));
}
return 0;
}
void initializedStack(stack *p){
p->top = 0;
}
void push(stack *p, int val){
p->top++;
p->items[p->top] = val;
}
int pop(stack *p){
int y;
y = p->items[p->top];
p->items[p->top] = 0;
(p->top)--;
return y;
}
我也检查了您的代码,没关系:
50
49
99
在控制台中,我得到了:
1
2
3
将浮点数舍入为小数点后两位:
float randFloat(float min, float max)
,响应为:
Random rand = new Random()
float min = 1.123456
float max = 10.568789
float result = (rand.nextFloat() * (max - min)) + min
println result