for(int i =0; i<3;i++)
{
for(int j =0; j< 4; j++)
{
sprintf(p, "0x%02x", rand()%256); // here i screwed when i use buf[i][j]
// any suggestions how to do. or any better method
}
Is there any better way for generation of hex and store.?
if its meant to be c++ code, then yes, you have <random> which is a far better generator tool.
if its C, as written, an alternate random library would outperform rand() which is recommended to be replaced for any serious code.
As jonnin mentions if using C++ there's the C++ stdlib <random> library. Still not the best random number generators available, none of the C++ engines are cryptographically secure. There are 3rd party libraries that are if needed.
Finding an alternative for C requires going 3rd party if you want to avoid <stdlib.h>.