* [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed
@ 2015-09-16 10:21 Josh Wu
2015-09-16 10:29 ` Andreas Bießmann
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Josh Wu @ 2015-09-16 10:21 UTC (permalink / raw)
To: u-boot
As 'time(0) | getpid()' will have a lot of duplicated value. It is not a
expected behavior. We expect different value for the seed when when run
it in many times.
So this patch will left shift the getpid() and add to time(0). That
avoid duplicated value.
Test command is like:
% RUN=0; while [ $RUN -lt 10000 ]; do
tools/gen_eth_addr; RUN=$(($RUN+1)); done | sort | uniq | wc -l
10000
This patch is incorporated with suggestions made by Wolfgang Denk and Andreas
Bie?mann. Thanks them a lot.
Signed-off-by: Josh Wu <josh.wu@atmel.com>
---
Changes in v2:
- left shift and add the getpid() value instead of removing it.
tools/gen_eth_addr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/gen_eth_addr.c b/tools/gen_eth_addr.c
index bf9d935..5fa3e0c 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() << 8));
/*
* setting the 2nd LSB in the most significant byte of
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed
2015-09-16 10:21 [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed Josh Wu
@ 2015-09-16 10:29 ` Andreas Bießmann
2015-09-16 12:56 ` Wolfgang Denk
2015-09-28 21:08 ` [U-Boot] [U-Boot, " Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Andreas Bießmann @ 2015-09-16 10:29 UTC (permalink / raw)
To: u-boot
On 09/16/2015 12:21 PM, Josh Wu wrote:
> As 'time(0) | getpid()' will have a lot of duplicated value. It is not a
> expected behavior. We expect different value for the seed when when run
when when ... could be fixed when applied
> it in many times.
>
> So this patch will left shift the getpid() and add to time(0). That
> avoid duplicated value.
>
> Test command is like:
> % RUN=0; while [ $RUN -lt 10000 ]; do
> tools/gen_eth_addr; RUN=$(($RUN+1)); done | sort | uniq | wc -l
> 10000
>
> This patch is incorporated with suggestions made by Wolfgang Denk and Andreas
> Bie?mann. Thanks them a lot.
>
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
Acked-by: Andreas Bie?mann <andreas.devel@googlemail.com>
> ---
>
> Changes in v2:
> - left shift and add the getpid() value instead of removing it.
>
> tools/gen_eth_addr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/gen_eth_addr.c b/tools/gen_eth_addr.c
> index bf9d935..5fa3e0c 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() << 8));
>
> /*
> * setting the 2nd LSB in the most significant byte of
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed
2015-09-16 10:21 [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed Josh Wu
2015-09-16 10:29 ` Andreas Bießmann
@ 2015-09-16 12:56 ` Wolfgang Denk
2015-09-28 21:08 ` [U-Boot] [U-Boot, " Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Denk @ 2015-09-16 12:56 UTC (permalink / raw)
To: u-boot
Dear Josh Wu,
In message <1442398864-1312-1-git-send-email-josh.wu@atmel.com> you wrote:
> As 'time(0) | getpid()' will have a lot of duplicated value. It is not a
> expected behavior. We expect different value for the seed when when run
> it in many times.
>
> So this patch will left shift the getpid() and add to time(0). That
> avoid duplicated value.
>
> Test command is like:
> % RUN=0; while [ $RUN -lt 10000 ]; do
> tools/gen_eth_addr; RUN=$(($RUN+1)); done | sort | uniq | wc -l
> 10000
>
> This patch is incorporated with suggestions made by Wolfgang Denk and Andreas
> Bie?mann. Thanks them a lot.
>
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> ---
>
> Changes in v2:
> - left shift and add the getpid() value instead of removing it.
>
> tools/gen_eth_addr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
I ran this version through a total of 80,000 runs ; there were no
duplicated addresses found in this test.
Acked-by: Wolfgang Denk <wd@denx.de>
Tested-by: Wolfgang Denk <wd@denx.de>
Thanks!
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
"Oh dear, I think you'll find reality's on the blink again."
- Marvin The Paranoid Android
^ permalink raw reply [flat|nested] 4+ messages in thread
* [U-Boot] [U-Boot, v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed
2015-09-16 10:21 [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed Josh Wu
2015-09-16 10:29 ` Andreas Bießmann
2015-09-16 12:56 ` Wolfgang Denk
@ 2015-09-28 21:08 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2015-09-28 21:08 UTC (permalink / raw)
To: u-boot
On Wed, Sep 16, 2015 at 06:21:04PM +0800, Josh Wu wrote:
> As 'time(0) | getpid()' will have a lot of duplicated value. It is not a
> expected behavior. We expect different value for the seed when when run
> it in many times.
>
> So this patch will left shift the getpid() and add to time(0). That
> avoid duplicated value.
>
> Test command is like:
> % RUN=0; while [ $RUN -lt 10000 ]; do
> tools/gen_eth_addr; RUN=$(($RUN+1)); done | sort | uniq | wc -l
> 10000
>
> This patch is incorporated with suggestions made by Wolfgang Denk and Andreas
> Bie?mann. Thanks them a lot.
>
> Signed-off-by: Josh Wu <josh.wu@atmel.com>
> Acked-by: Andreas Bie?mann <andreas.devel@googlemail.com>
> Acked-by: Wolfgang Denk <wd@denx.de>
> Tested-by: Wolfgang Denk <wd@denx.de>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150928/71531e23/attachment.sig>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-28 21:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-16 10:21 [U-Boot] [PATCH v2] tools: gen_eth_addr: add getpid() to time(0) to avoid duplicated seed Josh Wu
2015-09-16 10:29 ` Andreas Bießmann
2015-09-16 12:56 ` Wolfgang Denk
2015-09-28 21:08 ` [U-Boot] [U-Boot, " Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox