Here is the code where I am using uniqid script
<a href="" id="download" download="<?php echo uniqid(mt_rand(), true)?>-meme.png" >Download</a>
and the Javascript code
$('#download').click(function() {
var data = canvas.toDataURL();
download.href = data;
});
Here is the demo page.
When I click on download link a random name is generated but when I click no it again without refreshing the page I get the same filename?