In Bash, how to randomly select a file from a static list?

خرید بک لینک

I feel like this question is a homework assignment. Let me do it for you.

* in that script is likely retuing an alphabetized listing of a directory. So you could intercept that listing and randomize at that point.

You could also load the directory contents in to an array, randomly pick a number - mod the array size and if the result was empty, advance forward until you hit an non-empty entry. Then empty that entry as you consume it. You'd need a counter or something to then keep track of how many elements you've used so you know when you've consumed all entries.

Further, you could instead load the entries in to something like a linked-list and come up with a random entry # to consume and then discard from the data structure.

There are likely many other options. But I just gave you sketches for 3 crude approaches. Sure I didn't write code for you, but I did the hard part. You're welcome ;)

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 232 تاريخ: پنجشنبه 17 تير 1395 ساعت: 14:03

صفحه بندی