Generating a secure random number in javascript

What I am trying to do is generate a large (4096bit) random number in JavaScript that is cryptographically safe to use.

My approach is the following:

1. I am creating a Uint8Array with the desired length.
2. I am using Math.random() to prefill it.
3. I am showing a a 256x256pixel box, and show a message asking for moving the mouse around in it. For every onmousemove event, I am selecting a random byte in the array (using Math.random again), and doing a bitwise XOR with the relative X position of the mouse cursor, and doing the same to another random byte, with the Y position.
4. I keep processing onmousemove events until N events have been processed. (N >= a lot)

So what I have in the end is an array that was prefilled by an insecure random number generator, but whose output was mixed around with a lot of user-generated entropy.

My question is: Would the resulting number be safe to use? Or am I missing some glaring insecurity in this approach?

-
Over-engineered. Collect all mouse samples over some time $t$ (massively overestimate the time needed - better too much than not enough) instructing the user to furiously move the mouse around (do not record samples which occur more than twice in a row, it means he isn't moving his mouse), and feed it all into a hash function to distill 256 or 512 bits of entropy. Stretch as needed. That said you might look into existing frameworks to generate cryptographic numbers in Javascript - some already exist, and creating your own algorithm is generally not the answer. –  Thomas Jul 16 '13 at 14:15
I know there are existing frameworks. This is more of an exercise for myself. Trying to get into cryptographic thinking :) –  user7676 Jul 16 '13 at 14:19
–  CodesInChaos Jul 16 '13 at 14:34
Your approach is certainly much worse than hashing all the raw entropy with SHA-2 and then expanding it to the desired size. –  CodesInChaos Jul 16 '13 at 14:39
Right. So hashing is the answer, then. Thanks, guys! –  user7676 Jul 16 '13 at 15:01