获得随机数的错误总和

时间:2017-04-27 21:19:30

标签: c random

我正在进行骰子游戏,我需要掷骰子5次并将随机数加起来。一切都工作正常,但我的总和不是根据我得到的随机数

Expecting 6 cols, but line 5395818 contains text after processing all         
cols. Try again with fill=TRUE. Another reason could be that fread's    
logic in distinguishing one or more fields having embedded sep=','      
and/or (unescaped) '\n' characters within unbalanced unescaped quotes    
has failed. If quote='' doesn't help, please file an issue to figure 
out if the logic could be improved.

是骰子的两侧

2 个答案:

答案 0 :(得分:1)

您在显示信息时调用rand函数,然后在保存时再次调用,这解释了差异。

答案 1 :(得分:0)

function createMarkup() { return {__html: '<div className="msg"><p>Hello World</p></div>'}; } function MyComponent() { return <div dangerouslySetInnerHTML={createMarkup()} />; } 的每次调用都会返回一个新值。因此,您打印的值与您用于总和的值相同。

解决方案是仅调用rand一次并将结果保存在临时变量中。类似的东西:

rand