[U-Boot] [PATCH] tools: gen_eth_addr: remove getpid() operation for the random seed

Wolfgang Denk wd at denx.de
Wed Sep 16 08:37:01 CEST 2015


Dear Josh Wu,

In message <1442373526-842-1-git-send-email-josh.wu at atmel.com> you wrote:
> As 'time(0) | getpid()' sometimes get same value. That depends on the
> value of getpid().

I think removing some "random input" from the way how we compute the
seed is a bad idea.

> So that is not a expected behavior. We expect different value for the
> seed when when run it in many times.

What is your execution environment? In any sane OS it is higly
unlikely that you will see the same or even similar PIDs for
successive runs of the program - each run will start a new process,
which will get a new PID.

[On a mostly idle Linux system (4.1.6 kernel) I see zero dupes in a
set of 30,000 invocations of getpid().]

One can argue if ORing the values is the most clever idea, or if for
example ADDing them would result in more "randomness".  But completely
removing the pid() is bad - any parallel runs of the program on any
machines with synchronized times would predictably result in the same
seeds which is definitely worse behaviour than what we have now.

> So this patch remove the getpid(), just use the time(0) as the seed.

NAK.  This is a bad idea.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I program, therefore I am.


More information about the U-Boot mailing list