random colour xterm alias

I used to have this but do not know where it went - a script or an alias that:

opens a new xterm window with a random background colour.

I have this off "the internets" :
alias xterm1="xterm ... -bg \#* printf '%02x%02x%02x' {repeat 3 times $((RANDOM%128+128))}` &"

this gives me an alias: xterm1='xterm .. -bg \#8beaf7 &'
..which kind of works, but it's not elegant and it means that the window colouring is only random recursively.

any of you have a "better" version of this?

Put this in a script or a function:

n=200  ## adjust to taste: higher value, lighter background
n1=$(( 256 - $n ))
bg=$( printf "#%x%x%x\n" $(( $RANDOM % $n1 + $n )) \
                         $(( $RANDOM % $n1 + $n )) \
                         $(( $RANDOM % $n1 + $n )) )
xterm -bg "$bg" &
1 Like

works like a charm - thanks.