This works on OSX:
RANDOM := $(shell /bin/bash -c "echo $$RANDOM")
test: echo $(RANDOM)For cross platform random numbers I've instead resorted to this:
RANDOM := $(shell od -An -N2 -i /dev/random | tr -d ' ')How can I get the first example to work?
1 Answer
The reason your first line works on OSX and not Ubuntu, is likely because sh is bash on OSX. $$RANDOM is already expanded by the time the bash -c gets around to executing it, since you used "" quotes. So you probably want this:
RANDOM := $(shell bash -c 'echo $$RANDOM')Personally I'd probably go with awk. Something like
awk 'BEGIN{srand();printf("%d", 65536*rand())}'