
* On Thursday, June 04 2009, Bruce Stephens wrote:
Gwern Branwen
writes: [...]
Sure, but then he'd need to scale it. $RANDOM outputs between 0 and 32767, not 0-100.
OK, in zsh, something like:
printf %d $((RANDOM/327.67))
Of course, none of these are likely to be as good as just using python (or some other suitable language). For example the zsh example's not
Haskell:
import System.Random import Numeric import XMonad import Control.Monad
randomHex :: (Integral a, Random a) => (a, a) -> IO [Char] randomHex = fmap (concatMap $ ensure 2 . ($ "") . showHex) . replicateM 3 . randomRIO where ensure n = reverse . take n . (++repeat '0') . reverse
randomBg :: (Int,Int) -> X () randomBg x = do t <- asks terminal io $ spawn . ((t++" -bg '#")++) . (++"'") =<< randomHex x