hans030390
Diamond Member
I'm in an intro to computer science class, and there's one problem I can't quite figure out. I have to create a procedure, "pick-one-at-random" that will select one of two given arguments randomly (with equal probibility).
Examples:
> (pick-one-at-random 1 -1)
1
> (pick-one-at-random #t #f)
#f
> (pick-one-at-random #t 64)
#t
> ((pick-one-at-random + -) 3 4)
7
> (pick-one-at-random
(pick-one-at-random 1 2)
(pick-one-at-random 3 4))
4
My professor said to "think of it as flipping a coin, and one coin only" and that we only need to use "if" once in our code.
Can anyone provide and help or hints?
Examples:
> (pick-one-at-random 1 -1)
1
> (pick-one-at-random #t #f)
#f
> (pick-one-at-random #t 64)
#t
> ((pick-one-at-random + -) 3 4)
7
> (pick-one-at-random
(pick-one-at-random 1 2)
(pick-one-at-random 3 4))
4
My professor said to "think of it as flipping a coin, and one coin only" and that we only need to use "if" once in our code.
Can anyone provide and help or hints?