   long size = THCudaTensor_nElement(self);
   thrust::device_ptr<float> self_data(THCudaTensor_data(self));
   
-  thrust::sequence(self_data, self_data+size, 0);
-  thrust::transform(self_data, self_data+size, self_data, geometric_functor(p,step));
-  step+=size;
+  while (true) {
+      long bsize = size < MAXBLOCK ? size : MAXBLOCK;
+      thrust::sequence(self_data, self_data+bsize, 0);
+      thrust::transform(self_data, self_data+bsize, self_data, geometric_functor(p,step));
+      step+=bsize;
+      self_data+=bsize;
+      size-=bsize;
+      if (bsize == 0) break;
+  }
 
   THCudaTensor_freeCopyTo(self, self_);
 };

  long size = THCudaTensor_nElement(self);
  thrust::device_ptr<float> self_data(THCudaTensor_data(self));
  
  thrust::sequence(self_data, self_data+size, 0);
  thrust::transform(self_data, self_data+size, self_data, bernoulli_functor(p,step));
  step+=size;

  THCudaTensor_freeCopyTo(self, self_);
};

  long size = THCudaTensor_nElement(self);
  thrust::device_ptr<float> self_data(THCudaTensor_data(self));
  
  while (true) {
      long bsize = size < MAXBLOCK ? size : MAXBLOCK;
      thrust::sequence(self_data, self_data+bsize, 0);
      thrust::transform(self_data, self_data+bsize, self_data, random2_functor(a,b,step));
      step+=bsize;
      self_data+=bsize;
      size-=bsize;
      if (bsize == 0) break;
  }
  
  THCudaTensor_freeCopyTo(self, self_);
};

