This is more widely known as the two-envelope problem. Most commonly the amounts are given as $A$ and $2A$ but it's not required that this be the case.
Some points:
You cannot choose a random integer uniformly*, but the quoted part doesn't seem to require it be uniform. Choose a distribution - it doesn't matter what it is for the argument - as long as it has some probability of exceeding any finite value.
It wouldn't make sense to choose $d$ integer with the quoted decision rule, because money is discrete which means there's a nonzero chance $d=x$ and there's nothing listed for that case. (Or alternatively, to modify the rule to specify what to do when they're equal)
Leaving that aside, you could choose $d$ from some non-negative continuous distribution -- then we don't have to worry about equality.
* (nor can you choose a uniformly random non-negative integer nor a uniformly random positive integer)
If we say that there is a limit on the maximal amount of money, say $M$, or at least we choose $d$ from $1...M$, then the recipe boils down to the trivial advice of choosing $E_y$ if $x<M/2$ and choosing $E_x$ if $x>M/2$
If it turns out that the random distribution from which $x$ is chosen encompasses $M/2$ this should work (give you better than 50-50); if the distribution is stuck in one half it would not.
However, the versions of this game I was first presented with is that the envelope is presented by someone who (possibly) seeks to minimize your income from the game. The strategy of using a distribution to decide whether to switch to the other envelope will still work in that instance.