I am tasked withwant to code that will do the following exercise;:
Write a Mathematica function called
randomHop
that takes as its argument a list containing two coordinates x and y; your definition should begin
randomHop[{x_, y_}] :=
The function should then generate a random integer r equal to 1 or 2 (this should be locally scoped), and then
- if r is equal to 1, return {{0.5, 0.5}, {0.5, 0.5}} . {x, y};
- if r is 2, return {{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}.
I have so far tried
randomHop[{x_, y_}] := (
r = RandomInteger[{1, 2}]
If[r == 1, Return[{{0.5, 0.5}, {0.5, 0.5}}.{x, y}],
Return[{{-0.5, -0.5}, {0.5, -0.5}} . {x, y} + {1.0, 0}]])
but it's not working, and I don't know why. Any help would be appreciated.