MAX_OPERATIONS
ある口座から別の口座へ( ) 回の送金を実行したいと考えています。my-map
アカウントは、ハッシュ マップの呼び出し元(int アカウント ID、二重残高) に参照として格納されます。
送金は、ハッシュ マップから「ランダム インデックス」を取得し、それをaccount-from
に渡しtransfer
ます。両方を修正する必要がありますaccount-destination
。amount
残念ながら、私はそれを機能させることはできません。
(defn transfer [from-account to-account amount]
(dosync
(if (> amount @from-account)
(throw (Exception. "Not enough money")))
(alter from-account - amount)
(alter to-account + amount)))
(defn transfer-all []
(dotimes [MAX_OPERATIONS]
(transfer (get mymap (rand-int[MAX_ACCOUNT]) :account-id) account-destination amount)))