Corrected cuda device id selection
Updated code to fix randoms problem