it is 16byte only... i want to generate 16byte number .. please any clue to work on it?
Use arc4random 16 times, each time creating one byte. But if you want 16 bytes, I'll bet you want it for security reasons (encryption) in which case arc4random isn't good enough because it is only pseudo-random. What are you using it for?
Use arc4random 16 times, each time creating one byte. But if you want 16 bytes, I'll bet you want it for security reasons (encryption) in which case arc4random isn't good enough because it is only pseudo-random. What are you using it for?
thanks for the reply, i am using it for encryption purpose only , if it is pseudo random,how will i get a exact random number?please help me.
Use arc4random 16 times, each time creating one byte. But if you want 16 bytes, I'll bet you want it for security reasons (encryption) in which case arc4random isn't good enough because it is only pseudo-random. What are you using it for?
Bollocks.
arc4random is suitable for cryptographic use. ALL computer random number generators are pseudo-random. You need specialized hardware like scintillation detectors or noisy resistors to create truly random numbers. Pseudo-random numbers are the basis of much of computer cryptography.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
arc4random is suitable for cryptographic use. ALL computer random number generators are pseudo-random. You need specialized hardware like scintillation detectors or noisy resistors to create truly random numbers. Pseudo-random numbers are the basis of much of computer cryptography.
Duncan
I don't think arc4random is suitable because it is, as you say, pseudo random. Given the same seed, it always produces the same sequence of results. But SecRandomCopyBytes is different inthat it gets its randomness from the Linux: dev/random, which gets its randomness from a combination of unpredictable kernel events. There is even some speculation that the iPhone version of dev/random gets some input from the accelerometer. It may not be as good as noisy resistors, but it is certainly in a different class than arc4random.
If I wanted a very secure random sequence, I would probably call SecRandomCopyBytes numerous times over a long time period (several minutes) during which I was requesting input from the user. This input would cause more variations in Kernel events which would further increase the entropy in dev/random.
arc4random is suitable for cryptographic use. ALL computer random number generators are pseudo-random. You need specialized hardware like scintillation detectors or noisy resistors to create truly random numbers. Pseudo-random numbers are the basis of much of computer cryptography.
Duncan
i am checking it now,i think it will help me a lot thanks for all ....
I don't think arc4random is suitable because it is, as you say, pseudo random. Given the same seed, it always produces the same sequence of results. But SecRandomCopyBytes is different inthat it gets its randomness from the Linux: dev/random, which gets its randomness from a combination of unpredictable kernel events. There is even some speculation that the iPhone version of dev/random gets some input from the accelerometer. It may not be as good as noisy resistors, but it is certainly in a different class than arc4random.
If I wanted a very secure random sequence, I would probably call SecRandomCopyBytes numerous times over a long time period (several minutes) during which I was requesting input from the user. This input would cause more variations in Kernel events which would further increase the entropy in dev/random.
If you read the man page on arc4random(), it says:
The arc4random_stir() function reads data from /dev/urandom and uses it
to permute the S-Boxes via arc4random_addrandom().
There is no need to call arc4random_stir() before using arc4random(),
since arc4random() automatically initializes itself.
/dev/urandom is a system utility that maintains a pool of random seeds which is filled from "noise" in the system (like the timing for user actions, accelerometer data, jitter from the GPS, or whatever.) The details of the sources of system noise are platform-specific.
The system maintains an "entropy count" that tells it how much noise is available in this pool.
The one weakness in dev/urandom is that if the entropy count drops to zero, dev/urandom will start back at the beginning of the pool. That makes dev/urandom slightly less secure than dev/random, but with the benefit that it never blocks (aka causes your app to freeze). An equivalent system function, dev/random, blocks until the random seed pool collects more system noise.
I suspect that a handheld, network-connected, user-operated device like an iPhone/iPad/iPod touch is never lacking for abundant sources of system noise. The radio receivers are constantly receiving packets from the WiFi and/or cellular network with unpredictable (random) timing, the accelerometer magnetometer, and other sensors generate tons of very noisy data, etc.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
If you read the man page on arc4random(), it says:
The arc4random_stir() function reads data from /dev/urandom and uses it
to permute the S-Boxes via arc4random_addrandom().
There is no need to call arc4random_stir() before using arc4random(),
since arc4random() automatically initializes itself.
Ah, very good. I didn't realize that arc4random came from the same source. One possible concern is that if arc4random_stir is only called once the very first time you use arc4random, then the entropy is fixed at that time. It is deterministic from there on out. I might be concerned that a single snapshot from dev/random might not contain enough entropy to supply 128 bits of randomness. Explicitly calling arc4random_stir between bytes might be a good idea if you want in increase the randomness of a 16-byte array.
if i run arc4random() & 0xFF for 16times and if i append that into nsstring, will it become 16byte random number . I mean below is correct code for generating the 16byte radom number ? pleae help me?
NSMutableString *string = [[NSMutableString alloc]init];
for(int i = 0 ;i<16;i++)
{
// unsigned int a = arc4random()%65536;i was using this before
unsigned int a = arc4random() & 0xFF;
[string appendFormat:@"%llx",a];
}
NSLog(@"value of string is %@",string);
please help me
if i run arc4random() & 0xFF for 16times and if i append that into nsstring, will it become 16byte random number . I mean below is correct code for generating the 16byte radom number ? pleae help me?
NSMutableString *string = [[NSMutableString alloc]init];
for(int i = 0 ;i<16;i++)
{
// unsigned int a = arc4random()%65536;i was using this before
unsigned int a = arc4random() & 0xFF;
[string appendFormat:@"%llx",a];
}
NSLog(@"value of string is %@",string);
please help me
Please help me.
Last edited by prathibha; 09-15-2011 at 11:56 PM.
Reason: nobody replyed so