You are not logged in.
Pages: 1
Hi guys
how can I get the following script to remember the random numbers it's generated so far, so that it won't display the same image twice, unless there are 16+ terminals open? I guess I need some sort of permanent variable, but I don't know how to create such a thing.
#!/bin/bash
RANGE=16
RND=$RANDOM
let "RND %= $RANGE"
IMG=`ls ~/.urxvt/backgrounds/ | grep 0$RND-`
IMG_SIZE=`expr "$IMG" : '.*-([0-9]{2,}x[0-9]{2,})'`
echo $IMG_SIZE
urxvt -pixmap ~/.urxvt/backgrounds/$IMG -geometry $IMG_SIZE>> /dev/null 2>&1 &
Offline
You could always send the previous values to a file somewhere for reference. Or, I'd suggest switching to a better scripting language.
Offline
Yeah, I guess I ought to start using Python or Perl. I'm not sure which is best though... Perl's so powerful, but the syntax is so bizarre... I like the look of python. Has anyone who's used both got an opinion to share?
Offline
For the record, there's a million wallpaper randomizers out there - you'd be better off not reinventing the wheel and using an existing one.
Offline
Offline
No offence Phrakture, but what's better: me stealing someone else's code to randomize a terminal background, or writing one myself so that I get better at programming in whatever language I use?
Personally I think the latter would be more beneficial.
Offline
No offence Phrakture, but what's better: me stealing someone else's code to randomize a terminal background, or writing one myself so that I get better at programming in whatever language I use?
Personally I think the latter would be more beneficial.
Well, that's subjective. Personally, whenever I'm stuck with something, I try to work it out in my head, can't figure it out, then google and find how someone else has solved the problem. I learn best that way, by "stealing someone else's code" (it's not stealing if it's OSS).
It really depends on where your knowledge is at. When you do this sort of thing for a long time, languages begin to blur. Syntax is minor, it doesn't matter anymore. Knowing *how* to program is totally different. In my opinion, you don't learn how to write good code by practicing - you do it by looking at good code. It's similar to novel writting - you'll probably never have good prose and (...something else pertinent to writting a story...lol) if you've never read any books at all.
Offline
Yeah, I guess I ought to start using Python or Perl. I'm not sure which is best though... Perl's so powerful, but the syntax is so bizarre... I like the look of python. Has anyone who's used both got an opinion to share?
Perl is for old people that thought a dynamic language was cool when Perl came out. Python is for smart people who think its much cooler to have a decent dynamic language.
Yes, I've used both, and I can say with authority that Python is at least as powerful as Perl (and Java!) and the syntax is to die for.
Dusty
Offline
I agree completely with you Phrakture; knowing the methods and theory behind programming is far more important than knowing syntax. I'm a computer science student at Oxford University in the UK, and a lot of what we get taught is the theory behind programming, and the best way to approach a problem when coding.
Dusty, I'm glad to hear you're on the Python bandwagon; every comment I've seen about it was highly flattering. My tutor doesn't like it because it doesn't implement lambda very well (if you know what I'm talking about?); he uses Tcl with C, but personally I'd rather give Python a try.
Offline
Lisp!
Writing stories for a machine.
Offline
i always wondered, shouldn't that be lithp ?
Offline
LOL
Offline
Dusty, I'm glad to hear you're on the Python bandwagon; every comment I've seen about it was highly flattering. My tutor doesn't like it because it doesn't implement lambda very well (if you know what I'm talking about?); he uses Tcl with C, but personally I'd rather give Python a try.
I like python best out of the mass-of-dynamic-languages today (perl, ruby, groovy?, lush, ummm there's about 30 more). That is mainly due to clean syntax. I just like:
for a in someArray: #blah blah
much better than
someArray.each { |a|
#blah blah
}
Admittedly ruby is cool and all, but if I want oddly elegant code, I'll go for C++.
As for the "doesn't implement lambda correctly", that, to me, sounds like a regurgitated excuse... much like "java is slow" - I know the complaints about lambda, but they're very esoteric. I mean, you can write pages and pages of lambda functions and not run into any of the issues brought up by the opponents of the way it's implemented.
For the record, C++ supports lambda functions nicely:
std::vector<int> v;
//fill v with ints
//_1 is used to construct a lambda expression, _1 being the first argument
std::for_each(v.begin(),v.end(), std::cout << _1 << std::endl);
Offline
for a in someArray: #blah blah
much better than
someArray.each { |a| #blah blah }
someHash.each {
|key,value|
# blah blah
}
/me shrugs
to me that seems elegant. the object having the iteration method associated to it, instead of some global object iterator acting upon it.
probably a result of my programming origins though...
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
take you pick.
if ! [ -e /tmp/$RND ] ; then touch /tmp/$RND
or
if [ -e /tmp/$RND ] ; then
do
you need another draw
else
touch /tmp/$RND
do some more;
done
fi
the negated test is probably more clumbsy. remember to zap the /tmp files before or after, as required.
there is a good bash tutorial called abs or something, freshmeat ? abs-guide-rev.html.tar.gz is about what it is called revision is 3.0 or greater these days. I think it is also available as text
There is nothing intrinsically wrong with code theft, just get the right code.
Reading OPC is the fast way to learn.
--(*(cs25x--));
Offline
Python vs Ruby in a nutshell:
Python coders say "ruby is ok" and reby coders say "python is ok". People rarely say they love one and hate the other.
Not like the which distro or vi vs emacs debates.... or, within the python community, tabs vs spaces...
Dusty
Offline
Not like the which distro or vi vs emacs debates....
Dusty
I prefer vim.
Offline
why is it that every time I post in a thread its a marker that that thread has gone off topic? :'(
Dusty
Offline
LOL... just slow to get there, Dusty?
Offline
I guess so. Too busy. Been nice to have this break to harrass y'all again.... Too bad I can't delete posts anymore.... Ah the memories.... *sigh*
I feel so old.
Dusty
Offline
Pages: 1