gpt4 book ai didi

算法根据之前的结果调整 RNG

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:01:17 26 4
gpt4 key购买 nike

我正在尝试为我的模拟器重现一些行为。

我有一个百分比支票,从 30% 到 70% 不等。问题是它不是严格随机的。这是我提取的实时数据:

https://docs.google.com/spreadsheets/d/1JLXRxh7xvR_fYwnTtvQ72jNV0v4lHiEEY6o-kG52wQA/pubhtml

我从数据中注意到的一些事情:

  • 如果检查失败一次则增加下一次检查百分比
  • 70% 检查绝不会连续失败两次。
  • 所有第一轮的成功几率似乎都降低了 20%
  • 生成数据的服务器使用 PHP,因此它可能正在使用已知为伪随机的 rand() 函数

所以我想在 Java 中重现该行为。我可以编写自己的遵循这些模式的随机类,但我不确定我的实时数据是否涵盖所有情况,所以我想知道:现有的 PRNG 算法是否符合该行为?另外,我将如何调整机会以使全局比率保持在原始值附近?

最佳答案

这很简单,也很具体,不太可能,有人已经发过帖子了。成为第一名将是一种荣幸。

import java.util.Random;
public class FailGenerator {
private double firstChance;
private double nextChance;
private boolean first;
private boolean lastResult;
private Random r;

public FailGenerator(){
this(0.5, 0.7);
}
public FailGenerator(double firstChance, double nextChance){
this.firstChance = firstChance;
this.nextChance = nextChance;
first = true;
lastResult = true;
r = new Random();
}

public boolean didHeSucceed(){
if (lastResult == false){ //if he failed before
lastResult = true;
} else {
double chance;
if (first){
first = false;
chance = firstChance;
} else {
chance = nextChance;
}

if (r.nextDouble() <= chance){
lastResult = true;
} else {
lastResult = false;
}
}

return lastResult;
}
}

那么如果你这样调用它:

public static void main(String[] args) {
FailGenerator gen = new FailGenerator();
for (int i = 0; i < 50; i++) {
System.out.println("The result for iteration no. " + i + " is " + gen.didHeSucceed());
}
}

结果是这样的:

The result for iteration no. 0 is false
The result for iteration no. 1 is true
The result for iteration no. 2 is false
The result for iteration no. 3 is true
The result for iteration no. 4 is true
The result for iteration no. 5 is true
The result for iteration no. 6 is true
The result for iteration no. 7 is true
The result for iteration no. 8 is true
The result for iteration no. 9 is false
The result for iteration no. 10 is true
The result for iteration no. 11 is true
The result for iteration no. 12 is true
The result for iteration no. 13 is true
The result for iteration no. 14 is true
The result for iteration no. 15 is false
The result for iteration no. 16 is true
The result for iteration no. 17 is true
The result for iteration no. 18 is false
The result for iteration no. 19 is true
The result for iteration no. 20 is true
The result for iteration no. 21 is false
The result for iteration no. 22 is true
The result for iteration no. 23 is false
The result for iteration no. 24 is true
The result for iteration no. 25 is true
The result for iteration no. 26 is true
The result for iteration no. 27 is true
The result for iteration no. 28 is false
The result for iteration no. 29 is true
The result for iteration no. 30 is true
The result for iteration no. 31 is true
The result for iteration no. 32 is false
The result for iteration no. 33 is true
The result for iteration no. 34 is true
The result for iteration no. 35 is false
The result for iteration no. 36 is true
The result for iteration no. 37 is true
The result for iteration no. 38 is true
The result for iteration no. 39 is true
The result for iteration no. 40 is true
The result for iteration no. 41 is true
The result for iteration no. 42 is false
The result for iteration no. 43 is true
The result for iteration no. 44 is true
The result for iteration no. 45 is false
The result for iteration no. 46 is true
The result for iteration no. 47 is true
The result for iteration no. 48 is false
The result for iteration no. 49 is true

关于算法根据之前的结果调整 RNG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34722874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com