Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 11:18 on June 26, 2006


Practical 7] [36 election

[code]
#!/usr/bin/bash

Awk-V-V MAXNUM=$2 NUM=$1 '# transfer from Shell two vars
BEGIN (
# Get rand seed
Srand ()

# Check the numbers format
If ((NUM - /[0-9]+/) & (MAXNUM - /[0-9]+/))
        {
#print "Also published =" NUM "maxnum =" MAXNUM
        }
Else
        {
# Print error message
#print
#print "Syntax Error!"
Print
Print "Syntax : cmd_str num1 num2"
Print
Print "7 and 36 for default. "
#exit (1)

# Or give out default values
NUM=7
MAXNUM=36
        }
Print
Print "pick" NUM "of" MAXNUM
Print

Construct this array #
For (i=1;i<=NUM;i++)
        {
Do
                {
Selected=1+int (rand () *MAXNUM)
) While (selected in array)
Array[selected]=selected
        }

# Array to a pured indexed array
= 1
For (j in array)
        {
Sortarray[i++] = array[j]
        }

# Sort this indexed array
For (i=2; i<=NUM; ++i)
        {
For (j=i; (-1) in sortarray[j-1] sortarray, named "sortarray[j]; --j)
                {
Temperature = sortarray[j]
Sortarray[j] = sortarray[j-1]
Sortarray[j-1] = temperature
                }
        }

# Print after sort this array
For (i=1; i<=NUM; i++)
        {
Printf ( "%s" sortarray[i])
        }
Print
Print

) 'Transfer shell $* #' s args to awk

[/code]

Practical 7] [36 election

Sports Lottery election of bars; ) Yes! Dingyiding :)

Practical 7] [36 election

Welfare Lottery -

. /lotter.sh 7 36
. /lotter.sh 6 25
...

Practical 7] [36 election

[code]
If ((NUM - /[0-9]+/) & (MAXNUM - /[0-9]+/))
[/code]
Should be replaced
[code]
If ((NUM - /[0-9]+/) & (MAXNUM - /[0-9]+/) & (NUM "= MAXNUM))
[/code]
The first number can not be greater than the second, Death 哒

Practical 7] [36 election

Gawk version, about small change
[code]
#!/usr/bin/awk-F
BEGIN (
# Get rand seed
Srand ()
# Check the numbers format
While ((!NUM) | | (NUM - /[^0-9]/))
       {
NUM=7
Print
Printf "Input also published (default 7) :"


Getline NUM "" /dev/stdin "

       }
While ((!MAXNUM) | | (MAXNUM - /[^0-9]/))
       {
MAXNUM=36
Print
Printf "Input maxnum (default 36) :"


Getline MAXNUM "" /dev/stdin "

       }


Print
Print "pick" NUM "of" MAXNUM
Print

Construct this array #
For (i=1;i<=NUM;i++)
       {
Do
               {
Selected=1+int (rand () *MAXNUM)
) While (selected in array)
Array[selected]=selected
       }

# Array to a pured indexed array
= 1
For (j in array)
       {
Sortarray[i++] = array[j]
       }
# Sort this indexed array
For (i=2; i<=NUM; ++i)
       {
For (j=i; (-1) in sortarray[j-1] sortarray, named "sortarray[j]; --j)
               {
Temperature = sortarray[j]
Sortarray[j] = sortarray[j-1]
Sortarray[j-1] = temperature
               }
       }

# Print after sort this array
For (i=1; i<=NUM; i++)
       {
Printf ( "%s" sortarray[i])
       }
Print
Print

}  
[/code]

Practical 7] [36 election

37 7 election just five, at Running Lotteries see will work -

Practical 7] [36 election

China and the first prize, closely linked to a person mrgreen : 10000 :

Practical 7] [36 election

Oh. I have come to shell version :
[code]#!/bin/bash

Pick=$1
Pool=$2

Echo "$pick" - q | grep '[^0-9]' | | [z "$pick"], named pick=7
Echo "$pool" - q | grep '[^0-9]' | | [z "$pool"], named pool=36

P_array= ($ (seq $pool))

Get_nu () (
For ((i=1;i<=$1;i++)); Do
Echo ${p_array[$ ((RANDOM%pool)))
Done
}

${#s_nu[@]} -ne $pick Do [while]
S_nu= ($ (get_nu $pick | sort -un))
Done
Echo ${s_nu[@]}
[/code]

Practical 7] [36 election

Zhao Gongsui go! Perl the rand can also be used to generate a range of random number, such as :
[code]
Perl-e 'print (int rand (36))'
[/code]

Practical 7] [36 election

[Z "$pick"], named pick=7
Inform into pick=${pick=7}

Practical 7] [36 election

Bought a Note

Practical 7] [36 election

-->
You try the following two situations :
Pick=
Pick=abc

Reflections can come back?

Practical 7] [36 election

Receive and consider the implementation of the order wrong

Pick=$1
Pool=$2

Echo "$pick" - q | grep '[^0-9]' | | [z "$pick"], named pick=7
Echo "$pool" - q | grep '[^0-9]' | | [z "$pool"], named pool=36
Changed
Pick=$ ($ 1|sed echo 's/^[^0-9]*$/7/')
Pool=$ ($ 2|sed echo 's/^[^0-9]*$/36/')

: Mrgreen :

Practical 7] [36 election

Then :
Pick=007aa?

Practical 7] [36 election

Pick=$ (echo $pick|sed '/[^0-9]/d;s/^$/7/')
But this is not handled 001

Practical 7] [36 election

Waker have actually tested? ^_^

Practical 7] [36 election

Awk's faster than the shell?

Practical 7] [36 election

[waker@www D1]$ pick=a01;pick=$ (echo $pick|sed '/[^0-9]/s/^.*$//;s/^$/7/') ;echo $pick
7
[waker@www D1]$ pick=1;pick=$ (echo $pick|sed '/[^0-9]/s/^.*$//;s/^$/7/') ;echo $pick
1
[waker@www D1]$ pick=;pick=$ (echo $pick|sed '/[^0-9]/s/^.*$//;s/^$/7/') ;echo $pick
7

This seems to be under a thank net income

Practical 7] [36 election

I try the "miscellaneous Meeting"; )
[code]
#!/bin/ksh
#
(($#!=2)) | | (($ 1>=$2)) &&{ echo "Error!!!" ;exit 1;)
For i in $ (seq $ 2) ;do
Echo $ $i ((RANDOM%$2))
Done|sort -k2n|head -n$1|cut -f1-d '' |xargs echo
[/code]

Practical 7] [36 election



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com