在java中图片随机播放_java-以相同顺序随机播放多个文件

接下来仅使用基本的bash命令.原则是:

>生成随机顺序(数字)

>按此顺序订购所有文件

编码

#!/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

将使用下一个示例内容制作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.??

结果在我的笔记本上

real 1m13.404s

user 0m56.127s

sys 0m5.143s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值