如何生成与上一个不同的随机数

时间:2016-06-10 12:15:18

标签: swift random

在我说什么之前,请注意这不是重复: **

This Question

因为我已尝试使用该问题的所有答案,但由于UINT32,它们都会出现错误。

那么,如何使用arc4random生成随机数,但不能使其与上次相同?

1 个答案:

答案 0 :(得分:0)

这是一个不使用UINT32

的解决方案
function drag_start(event) {
    var style = window.getComputedStyle(event.target, null);
    event.dataTransfer.setData("text/plain",
    (parseInt(style.getPropertyValue("left"),10) - event.clientX) + ',' + (parseInt(style.getPropertyValue("top"),10) - event.clientY));
} 
function drag_over(event) { 
    event.preventDefault(); 
    return false; 
} 
function drop(event) { 
    var offset = event.dataTransfer.getData("text/plain").split(',');
    var dm = document.getElementById('dragme');
    dm.style.left = (event.clientX + parseInt(offset[0],10)) + 'px';
    dm.style.top = (event.clientY + parseInt(offset[1],10)) + 'px';
    var pos = {left: dm.style.left, top: dm.style.top};
    console.log( pos );
    localStorage.setItem("div_position", JSON.stringify(pos));
    event.preventDefault();
    return false;
}
var dm = document.getElementById('dragme'); 
try {
  var pos = JSON.parse(localStorage.getItem("div_position"));
  dm.style.left = pos.left ? pos.left : '0px';
  dm.style.top = pos.top ? pos.top : '0px';
} catch (e) {
  // Some error handling
}
dm.addEventListener('dragstart',drag_start,false); 
document.body.addEventListener('dragover',drag_over,false); 
document.body.addEventListener('drop',drop,false); 


/*

function drop(event) { 
    var offset = event.dataTransfer.getData("text/plain").split(',');
    var dm = document.getElementById('dragme');
    dm.style.left = (event.clientX + parseInt(offset[0],10)) + 'px';
    dm.style.top = (event.clientY + parseInt(offset[1],10)) + 'px';
    var pos = {left: dm.style.left, top: dm.style.top};
    var str = JSON.stringify(pos);
    var dat = <?php echo $_GET[date];?>;
    document.cookie = dat+"="+str;
    event.preventDefault();
    return false;
}
var dm = document.getElementById('dragme'); 
try {
  var pos = JSON.parse(dat);
  dm.style.left = pos.left ? pos.left : '0px';
  dm.style.top = pos.top ? pos.top : '0px';
} catch (e) {
  // Some error handling
}
*/