Re: How to use 'get_random_bytes'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > For being sure I use 'get_random_bytes' in a correct way, I would
> > like to ask if somebody could post which parameters I have to fill
in
> > if I want to get an integer 'x' with random numbers and let's say
the
> > whole thing 3 bytes long.  Is it really
> >
> >     int x;
> >     get_random_bytes(x, 3);
>
> No, not at all.  This suggests C isn't a language you feel confident
> in.  I'd stop doing any kernel stuff until the answer to this
question
> is second nature.  Kernighan and Ritchie's _The C Programming
> Language_, 2nd Ed., is what you need to read.

Sorry, it was late and I was tired... Of course the code written above
isn't worth to mention...

>
>     int i;
>     int *ip;
>
>     ip = &i;
>     get_random_bytes(&i, sizeof i);
>     get_random_bytes(ip, sizeof *ip);

Yes, this seems to make more sense. The only thing I'm a little bit
unsure about is why 'get_random_bytes' is called twice. The first time
it gets the address of 'i' and it's size which is int. The next time
it gets 'ip' which is equal to the address of 'i' (ip=&i;) and should
have the size of int, too (int *ip).

I hope the question isn't too stupid, but I'm in a hurry (I have to go
to school in a few minutes) and didn't check it with my C Reference. I
do it this way because I would like to start to code the lottery
scheduler this evening and the earlier I find a _working_ way to get
random numbers into an integer the faster I can start with the real
fun, with implementing the algorithm...

Thank you
Sven

-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux