[system] / trunk / webwork / system / courseScripts / PGbasicmacros.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/webwork/system/courseScripts/PGbasicmacros.pl

Revision 462 Revision 463
760 760
761 Usage: 761 Usage:
762 random(0,5,.1) # produces a random number between 0 and 5 in increments of .1 762 random(0,5,.1) # produces a random number between 0 and 5 in increments of .1
763 non_zero_random(0,5,.1) # gives a non-zero random number 763 non_zero_random(0,5,.1) # gives a non-zero random number
764 764
765 list_random(2,3,5,6,7,8,10) # produces random value from the list
766 list_random(2,3, (5..8),10) # does the same thing
767
765 SRAND(seed) # resets the main random generator -- use very cautiously 768 SRAND(seed) # resets the main random generator -- use very cautiously
766 769
767 770
768SRAND(time) will create a different problem everytime it is called. This makes it difficult 771SRAND(time) will create a different problem everytime it is called. This makes it difficult
786 my \$i=100; #safety counter 789 my \$i=100; #safety counter
787 while (\$a==0 && ( 0 < \$i-- ) ) { 790 while (\$a==0 && ( 0 < \$i-- ) ) {
788 \$a=random(@arguments); 791 \$a=random(@arguments);
789 } 792 }
790 \$a; 793 \$a;
794}
795
796sub list_random {
797 my(@li) = @_;
798 return \$li[random(1,scalar(@li))-1];
791} 799}
792 800
793sub SRAND { # resets the main random generator -- use cautiously 801sub SRAND { # resets the main random generator -- use cautiously
794 my \$seed = shift; 802 my \$seed = shift;
795 \$main::PG_random_generator -> srand(\$seed); 803 \$main::PG_random_generator -> srand(\$seed);

Legend:
 Removed from v.462 changed lines Added in v.463