What is the origins of the phrase dicing with death?

Two guilty men were sentenced to death but the presiding judge was in a lenient mood and offered one man his freedom. To decide who should be released the men each rolled a die. The man who rolled the higher number was released, and the other executed. Hence dicing with death.