10 — Random: dice and picks
Games need surprises. NME bundles a random helper that Python provides, loaded
with one use line.
Steps
Create
dice.nme:
run it →use random latest set die to random number from 1 to 6 show dieRun it a few times:
dieis a random whole number from 1 to 6.Picking one of several choices works the same way:
run it →use random latest set color to pick from red or green or blue show colorKorean loads the helper with
랜덤 사용 최신and uses sentence endings:
run it →랜덤 사용 최신 주사위는 1부터 6까지 랜덤정수 주사위 보여줘 색은 빨강 또는 초록 또는 파랑 중에서 랜덤선택 색 보여줘The helper names work in expressions too:
랜덤정수(a, b)is a random number and랜덤선택(values)picks from a list.
run it →use random latest set roll to random number from 1 to 6 show roll
Try it yourself
Roll two dice and show both:
use random latest
set first to random number from 1 to 6
set second to random number from 1 to 6
show first
show second
run it →What you learned
use random latest/랜덤 사용 최신loads the bundled random helper.random number from 1 to 6/1부터 6까지 랜덤정수roll a die.pick from red or green or blue/... 중에서 랜덤선택pick one choice.use filemay joinuse randomin the same program — guide 15 saves its best score that way.