One way would be to assign it a class and then just use jQuery to get the id such as this:
$('.check-id').on('click', function(){
alert($(this).parent().attr('id'));
});
Your div would look like this:
<div id="rnd()"><button class="check-id">Click</button></div>
With the above approach you can have many buttons and divs and this would work. You just have to make sure to assign a check-id class to the button.