Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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())}'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.