On Wednesday 26 May 2010 18:16:18 Brandon McCaig wrote: > On Wed, May 26, 2010 at 9:43 AM, Andros Zuna <andros.z...@gmail.com> wrote: > > But how could I test if the command executes if the return value changes? > > ...is there a unix command or other way that generates random/different > > return values?? > > The following C program will return a pseudo-random value every time it's > run: > > // --BEGIN-- > #include <stdlib.h> > > int main(int argc, char * argv[]) > { > srand(time(0)); > > return rand() % 256; > } > > // --END-- > > Save it into a file (i.e., main.c) and compile it with GCC: > > gcc main.c -o rand > > Then, you can execute the program. > > ./rand > > Though if you're only concerned with zero and non-zero then there's > little reason for the range of return values that I've allowed for > (0-255). You could probably get away with changing... > > return rand() % 256; > > ...to... > > return rand() % 2; > > That will probably increase the likelihood of encountering 0. > > (Sorry for the C on a Perl mailing list :P)
You can also do the same in Perl using "perldoc -f exit" # Untested #!/usr/bin/perl srand() exit(rand()%2); Though you can naturally use false or test for such things too. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Freecell Solver - http://fc-solve.berlios.de/ God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/