你好,我有这个随机产生的功能:a,b,c或d。
number1 = (int)(Math.random()* LT) + 1;
number2 = (int)(Math.random()* LT) + 1;
operator = (int)(Math.random()* OP) + 1;
switch(operator) {
case 1:
operation = "+";
result = number1 + number2;
break;
case 2:
operation = "-";
result = number1 - number2;
break;
case 3:
operation = "*";
result = number1 * number2;
break;
case 4:
operation = "/";
result = number1 * number2;
break;
}
这意味着我有4个可能的随机输出。但我想建立一个recusrsive函数,在我给出的数字作为参数之间输出。
例如:
随机 - 我的3 - >给出和输出:a b或c
随机 - 我的5 - >给出和输出:a b c d或e
谢谢!
答案 0 :(得分:1)
答案 1 :(得分:1)
尝试:
Callback: Ether / ARP who has 10.0.0.15 says 10.0.0.1
Received: Ether / ARP who has 10.0.0.15 says 10.0.0.1
Callback: Ether / ARP is at xx:xx:xx:xx:xx:xx says 10.0.0.15
Received: Ether / ARP is at xx:xx:xx:xx:xx:xx says 10.0.0.15
Callback: Ether / IP / TCP ... PA / Raw
Received: Ether / IP / TCP ... PA / Raw
Callback: Ether / IP / TCP ... PA / Raw
Received: Ether / IP / TCP ... PA / Raw
Callback: Ether / IP / TCP ... FPA / Raw
Received: Ether / IP / TCP ... FPA / Raw
...
答案 2 :(得分:1)
您可以传递一个n
号码,然后您可以(random n)
获取r
范围内的随机数[0,n>
。现在#\a
的字符编号为97
,因此如果您(integer->char (+ 97 r))
#\a
0
,#\b
1
,...
您可以使用(list->string (list #\a)) ; ===> "a"
获取字符串。
您可以使用(string->symbol "a") ; ==> a
我留给你把它放在一起,但它不是递归的。
答案 3 :(得分:0)
递归fn生成n个字母的随机列表,直到第n个字母:
(define (f n (ol '()))
(if (= n (length ol))
ol
(f n (cons (string (integer->char (+ 97 (random n)))) ol))))
测试:
(f 5)
输出:
'("b" "d" "b" "e" "e") ; list will have random letters;