Click here to Skip to main content
16,011,757 members

Comments by aruidsp (Top 4 by date)

aruidsp 4-Feb-11 21:34pm View    
Hi SA,

Thanks.

But it returns more than 8 digit random number.
I assigned numbytes = 4 and run my code, it returns more than 8 digits.
But I need always an 8 digit random number only.

Thanks.
aruidsp 3-Feb-11 9:26am View    
Hi SA,

Thanks for the update.
I have some issue with the code.
here is my code.

byte Random()
{
RNGCryptoServiceProvider random = new RNGCryptoServiceProvider();
byte[] randomBytes = new byte[4];
random.GetBytes(randomBytes);
return randomBytes;
}


public int randomint()
{
byte numBytes = sizeof(int);
int value = 0;
for (int index = 0; index < numBytes; index++)
value |= Random() << index * 8;

return value;
}


Now the randomBytes can not convert to byte.

Thanks.
aruidsp 2-Feb-11 23:29pm View    
Thanks for code but I don't want use the random class.
aruidsp 2-Feb-11 23:28pm View    
Hi SA,

Thanks a lot for the code.

The field value never assigned any value.
is it as below

index |= Random() << index * 8;

value = index;
return value;

Thanks,
Uday