我需要使用UNIX指挥线的文字,从一起整理的档案中抽取11条随机线。 例
Random source file:
1
2
3
4
5
6
7
8
9
10
11
############
12
13
14
15
16
17
18
19
20
21
22
页: 1 请让我:
1
2
3
4
5
6
7
8
9
10
11
或
12
13
14
15
16
17
18
19
20
21
22
我需要使用UNIX指挥线的文字,从一起整理的档案中抽取11条随机线。 例
Random source file:
1
2
3
4
5
6
7
8
9
10
11
############
12
13
14
15
16
17
18
19
20
21
22
页: 1 请让我:
1
2
3
4
5
6
7
8
9
10
11
或
12
13
14
15
16
17
18
19
20
21
22
tail -n +$(($RANDOM %
($(wc -l "$filename" | cut -d -f1) - 11))) "$filename" |
head -n 11
页: 1
export filename=/etc/dictionaries-common/words
set -o xtrace
第一次
~$ tail -n +$(($RANDOM % ($(wc -l "$filename" | cut -d -f1) - 11))) "$filename" | head -n 11
+ head -n 11
++ wc -l /etc/dictionaries-common/words
++ cut -d -f1
+ tail -n +11614 /etc/dictionaries-common/words
Moriarty s
Morin
Morin s
Morison
Morison s
Morita
Morita s
Morley
Morley s
Mormon
Mormon s
第二次
~$ tail -n +$(($RANDOM % ($(wc -l "$filename" | cut -d -f1) - 11))) "$filename" | head -n 11
+ head -n 11
++ wc -l /etc/dictionaries-common/words
++ cut -d -f1
+ tail -n +1661 /etc/dictionaries-common/words
Beatrice
Beatrice s
Beatrix
Beatrix s
Beatriz
Beatriz s
Beau
Beau s
Beaufort
Beaufort s
Beaujolais
你可以尝试:
n=$((`wc -l "${file}" | cut -d -f1` / 11))
m=$(($RANDOM % $n))
tail -n +$(($m * 11)) "${file}" | head -n 11
I m trying to implement a weighted random numbers. I m currently just banging my head against the wall and cannot figure this out. In my project (Hold em hand-ranges, subjective all-in equity ...
There are a lot of questions about salts and best practices, however most of them simply answer very specific questions about them. I have several questions which feed into one another. Assuming a ...
I am working on a php site in which we have to upload images from users.i have to rename that file for preventing conflicts in the name of the image. uniqid(rand(), true); and adding a large random ...
How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.
According to various sources, such as Wikipedia and various .edu websites found by Google, the most common ways for a hash table to resolve collisions are linear or quadratic probing and chaining. ...
I m pulling my hair out trying to build a little random photo JSON feed using DataMapper/Sinatra. Here s what I have so far.. Photo.favorites.to_json(:methods => [:foo, :bar]) So that works fine. ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I have two animation sequences, and I want one of them to play randomly when a button is pressed. Here is the code: { color.animationImages = [NSArray arrayWithObjects: [...