public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Josh Wu <josh.wu@atmel.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] tools: gen_eth_addr: remove getpid() operation for the random seed
Date: Wed, 16 Sep 2015 17:53:35 +0800	[thread overview]
Message-ID: <55F93C1F.4080906@atmel.com> (raw)
In-Reply-To: <20150916091511.5238F380905@gemini.denx.de>

Hi, Wolfgang, Andreas

Thanks for the testing and point out the wrongness in my patch.

On 9/16/2015 5:15 PM, Wolfgang Denk wrote:
> Dear Josh,
>
> In message <55F91588.3040305@atmel.com> you wrote:
>> In above commands, I have two duplicated eth addr:
>> 92:33:16:3f:0a:56
>> d2:41:66:54:64:aa
> Agreed. Randomness is really poor; for a sequence of 1000 invocations
> of gen_eth_addr in a shell loop I would only gt 124 different MAC
> addresses:
>
> -> for i in {1..1000} ; do ./gen_eth_addr ; done >/tmp/0
> -> sort -u /tmp/0 >/tmp/1 ; wc -l /tmp/[01]
>   1000 /tmp/0
>    124 /tmp/1
>
> In a second run, even only 41 :-(
>
> But without the getpid() part, it gets even worse - the same loop
> would produce only 15 different addresses!
>
>
> Changing the '|' into a '+' would reliably generate 1000 different MAC
> addresses.
>
>> I understand your concern. My intention is make it harder to generate
>> the duplicated result.
> I understand this, and agree that we should implement such a fix.
>
>> Maybe we can ORing the MSB of time(0)?
>> I'll investigate it little more.
> The following patch appears to work fine for me.  Maybe you can test
> it?

yes, this one works well. if you don't mind I want to sent v2 patch, 
which is like:

-    srand(time(0) | getpid());
+    srand(time(0) + (getpid() << 8));


>
> diff --git a/tools/gen_eth_addr.c b/tools/gen_eth_addr.c
> index bf9d935..834163a 100644
> --- a/tools/gen_eth_addr.c
> +++ b/tools/gen_eth_addr.c
> @@ -15,7 +15,7 @@ main(int argc, char *argv[])
>   {
>       unsigned long ethaddr_low, ethaddr_high;
>   
> -    srand(time(0) | getpid());
> +    srand(time(0) + getpid());
>   
>       /*
>        * setting the 2nd LSB in the most significant byte of
>
>
> Thanks.
>
> Best regards,
>
> Wolfgang Denk
>

Best Regards,
Josh Wu

  reply	other threads:[~2015-09-16  9:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16  3:18 [U-Boot] [PATCH] tools: gen_eth_addr: remove getpid() operation for the random seed Josh Wu
2015-09-16  6:37 ` Wolfgang Denk
2015-09-16  7:08   ` Josh Wu
2015-09-16  7:27     ` Josh Wu
2015-09-16  9:15     ` Wolfgang Denk
2015-09-16  9:53       ` Josh Wu [this message]
2015-09-16  8:23 ` Andreas Bießmann
2015-09-16  9:12   ` Josh Wu
2015-09-16  9:26     ` Andreas Bießmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55F93C1F.4080906@atmel.com \
    --to=josh.wu@atmel.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox