A slight addition to the existing answers:
If B has not downloaded enough of the block chain to see A's transaction, then the situation will be as described above. When blocks are downloaded by a wallet client, the transactions therein are checked to see whether any of them send coins to addresses held in this wallet. If so, those coins are added to the wallet's balance. So B will see an extra 25 BTC appear in his wallet. As mentioned in the other answers, he'll be able to spend them as if they were his own. So it's a race between A and B to see who spends them first - either can do it.
If B has already downloaded the relevant transactions before generating the colliding address, the situation is a little different. As far as I know, most Bitcoin clients, when generating a fresh random address, will not rescan the block chain to see whether it contains any transactions sending coins to that address. (As described above, the probability of this happening is infinitesimally small, so for all practical purposes, such a scan would just be a waste of time and resources.) So although B now has a private key which can spend A's bitcoins, he will not be aware of it, unless/until he manually forces a block chain rescan (e.g. with Bitcoin Core's -rescan option), or checks his address balance using an online block explorer, or something of the kind.
Of course, barring RNG faults, this question is sort of like asking "If all 50 US state governors were simultaneously struck by lightning, how would the stock market be affected?" It's based on such an improbable assumption that it's kind of absurd to draw any conclusion.
10They'd be able to spend each other's coins. – Nick ODell – 2013-02-16T20:54:11.577
1
related: How many Bitcoin addresses are there?, Is it possible to brute force bitcoin address creation in order to steal money?
– Murch – 2014-03-24T12:51:49.053doesn't labeling the address help solve some of that problem? – None – 2014-03-24T21:44:51.953
@rponder No, the labels you attach to some addresses are just on your own computer. – Murch – 2014-03-24T22:28:36.213
1
Well, it has already happened. Someone has already collected $8,000 of btc that came from Android clients that failed to properly generate random numbers. See http://arstechnica.com/security/2015/05/crypto-flaws-in-blockchain-android-app-sent-bitcoins-to-the-wrong-address/
– None – 2015-10-08T07:58:36.357@SaintHill oh wow, that's bad – Austin Burk – 2015-10-09T02:50:12.790
2Generate the same keypair hash (AKA collision) equals the chances of Chloë Grace Moretz be my gf, 1,461,501,637,330,902,918,203,684,832,716,283,019,655,932,542,976 of possible addresses, how many chances do you think you have? – D.Snap – 2016-04-06T19:14:22.187