Jaren Stangret
2013-Mar-20 03:29 UTC
[flac-dev] [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
Erik, I was thinking of doing this: export MALLOC_PERTURB_=$(awk 'BEGIN { srand(); print int(rand() * 32767 % 255 + 1) }') Or would you prefer using 'date'? On Tue, Mar 19, 2013 at 10:22 PM, Erik de Castro Lopo <mle+la at mega-nerd.com>wrote:> Jesse Weinstein wrote: > > > The subject line mostly says it all, but for reference, having #!/bin/sh > causes the following error: > > > > arithmetic expression: expecting primary: " % 255 + 1" > > Arithmetic support is actually not the issue, rather its that dash/sh > doesn't support $RANDOM. The solution to this is to replace $RANDOM > with $(date +%N) which is obviouslsy not all that random, but which > is close enough to random for this usage. > > Since Jaren is in the process of making the scripts POSIX shell > compliant, I think swicthing to bash is a bad idea :-). > > I was going to do the $RANDOM to $(date +%N) conversion after Jaren's > POSIX patches were all applied. > > Cheers, > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > _______________________________________________ > flac-dev mailing list > flac-dev at xiph.org > http://lists.xiph.org/mailman/listinfo/flac-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20130319/03f15ffb/attachment.htm
Jaren Stangret
2013-Mar-20 03:31 UTC
[flac-dev] [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
Which I think srand actually uses 'date' as it's seed in this case... On Tue, Mar 19, 2013 at 10:29 PM, Jaren Stangret <sirjaren at gmail.com> wrote:> Erik, > > I was thinking of doing this: > export MALLOC_PERTURB_=$(awk 'BEGIN { srand(); print int(rand() * 32767 % > 255 + 1) }') > > Or would you prefer using 'date'? > > > On Tue, Mar 19, 2013 at 10:22 PM, Erik de Castro Lopo < > mle+la at mega-nerd.com> wrote: > >> Jesse Weinstein wrote: >> >> > The subject line mostly says it all, but for reference, having >> #!/bin/sh causes the following error: >> > >> > arithmetic expression: expecting primary: " % 255 + 1" >> >> Arithmetic support is actually not the issue, rather its that dash/sh >> doesn't support $RANDOM. The solution to this is to replace $RANDOM >> with $(date +%N) which is obviouslsy not all that random, but which >> is close enough to random for this usage. >> >> Since Jaren is in the process of making the scripts POSIX shell >> compliant, I think swicthing to bash is a bad idea :-). >> >> I was going to do the $RANDOM to $(date +%N) conversion after Jaren's >> POSIX patches were all applied. >> >> Cheers, >> Erik >> -- >> ---------------------------------------------------------------------- >> Erik de Castro Lopo >> http://www.mega-nerd.com/ >> _______________________________________________ >> flac-dev mailing list >> flac-dev at xiph.org >> http://lists.xiph.org/mailman/listinfo/flac-dev >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20130319/bf386592/attachment-0001.htm
Erik de Castro Lopo
2013-Mar-20 06:24 UTC
[flac-dev] [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
Jaren Stangret wrote:> Erik, > > I was thinking of doing this: > export MALLOC_PERTURB_=$(awk 'BEGIN { srand(); print int(rand() * 32767 % > 255 + 1) }') > > Or would you prefer using 'date'?Your's is probably better and this is probably an improvement: awk 'BEGIN { srand(); print int(rand() * 255 + 1) }' Awk's rand seems to be seeded by the current epoch seconds, but in this case that doesn't matter. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
Jaren Stangret
2013-Mar-20 17:55 UTC
[flac-dev] [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
> > Your's is probably better and this is probably an improvement: >awk 'BEGIN { srand(); print int(rand() * 255 + 1) }'>Awk's rand seems to be seeded by the current epoch seconds, but in this> case that doesn't matter.Looks good to me. I'd even go as far as implementing your nanosecond approach as the seed for AWK's 'srand()'. Maybe set up a tiny function to use whenever we want a random integer: random_int () { awk \ -v nanosecond_seed=$(date +%N) \ 'BEGIN { srand( nanosecond_seed ) print int ( rand() * 255 + 1 ) }' } Then we can just call 'random_int' in place of $RANDOM... On Wed, Mar 20, 2013 at 1:24 AM, Erik de Castro Lopo <mle+la at mega-nerd.com>wrote:> Jaren Stangret wrote: > > > Erik, > > > > I was thinking of doing this: > > export MALLOC_PERTURB_=$(awk 'BEGIN { srand(); print int(rand() * 32767 % > > 255 + 1) }') > > > > Or would you prefer using 'date'? > > Your's is probably better and this is probably an improvement: > > awk 'BEGIN { srand(); print int(rand() * 255 + 1) }' > > Awk's rand seems to be seeded by the current epoch seconds, but in this > case that doesn't matter. > > Erik > -- > ---------------------------------------------------------------------- > Erik de Castro Lopo > http://www.mega-nerd.com/ > _______________________________________________ > flac-dev mailing list > flac-dev at xiph.org > http://lists.xiph.org/mailman/listinfo/flac-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20130320/69c088bd/attachment-0001.htm
Possibly Parallel Threads
- [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
- [PATCH] Change test scripts shell to bash, to avoid lack of arithmetic support in dash, which is sh on Ubuntu 10.04
- [PATCH] Prepend local library path to LD_LIBRARY_PATH for tests, instead of replacing it
- [flac 1.3.0pre2 pre-release] Updates to test suite
- [flac 1.3.0pre2 pre-release] Updates to test suite