在java中图片随机播放_java-以相同顺序随机播放多个文件
接下來僅使用基本的bash命令.原則是:
>生成隨機順序(數(shù)字)
>按此順序訂購所有文件
編碼
#!/bin/bash
case "$#" in
0) echo "Usage: $0 files....." ; exit 1;;
esac
ORDER="./.rand.$$"
trap "rm -f $ORDER;exit" 1 2
count=$(grep -c '^' "$1")
let odcount=$(($count * 4))
paste -d" " $ORDER
#if your system has the "shuf" command you can replace the above 3 lines with a simple
#seq -w $count | shuf > $ORDER
for file in "$@"
do
paste -d' ' $ORDER $file | sort -k1n | cut -d' ' -f2- > "$file.rand"
done
echo "the order is in the file $ORDER" # remove this line
#rm -f $ORDER # and uncomment this
# if dont need preserve the order
paste -d " " *.rand #remove this line - it is only for showing test result
從輸入文件中:
A B C
--------
a1 a2 a3
b1 b2 b3
c1 c2 c3
d1 d2 d3
e1 e2 e3
f1 f2 f3
g1 g2 g3
h1 h2 h3
i1 i2 i3
j1 j2 j3
將使用下一個示例內(nèi)容制作A.rand B.rand C.rand
g1 g2 g3
e1 e2 e3
b1 b2 b3
c1 c2 c3
f1 f2 f3
j1 j2 j3
d1 d2 d3
h1 h2 h3
i1 i2 i3
a1 a2 a3
真實測試-用25k行生成50個文件
line="Consequatur qui et qui. Mollitia expedita aut excepturi modi. Enim nihil et laboriosam sit a tenetur."
for n in $(seq -w 50)
do
seq -f "$line %g" 25000 >file.$n
done
運行腳本
bash sorter.sh file.??
結(jié)果在我的筆記本上
real 1m13.404s
user 0m56.127s
sys 0m5.143s
總結(jié)
以上是生活随笔為你收集整理的在java中图片随机播放_java-以相同顺序随机播放多个文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 修改SDE中自动生成的web.xml文件
- 下一篇: MySQL电影院管理系统_电影院售票管理