Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将方法Rand(int)Visual Fox Pro迁移到C.net_C#_Asp.net_.net_Foxpro_Visual Foxpro - Fatal编程技术网

C# 将方法Rand(int)Visual Fox Pro迁移到C.net

C# 将方法Rand(int)Visual Fox Pro迁移到C.net,c#,asp.net,.net,foxpro,visual-foxpro,C#,Asp.net,.net,Foxpro,Visual Foxpro,我正在将Visual Fox Pro代码迁移到C。网 是什么让Visual Fox Pro: 根据文本框中捕获的文本字符串生成一个5位数的字符串48963,如果始终输入相同的文本字符串,则该字符串将始终为5位数,无反转,我的代码为C。NET应该生成相同的字符串 我想将下面的代码Visual Fox Pro 6迁移到C gnLower = 1000 gnUpper = 100000 vcad = 1 For y=gnLower to gnUpper step 52 genClave = *

我正在将Visual Fox Pro代码迁移到C。网

是什么让Visual Fox Pro: 根据文本框中捕获的文本字符串生成一个5位数的字符串48963,如果始终输入相同的文本字符串,则该字符串将始终为5位数,无反转,我的代码为C。NET应该生成相同的字符串

我想将下面的代码Visual Fox Pro 6迁移到C

gnLower = 1000
gnUpper = 100000
vcad = 1
For y=gnLower to gnUpper step 52
    genClave = **Rand(vcad)** * y
    vRound = allt(str(int(genclave)))
    IF Len(vRound) = 3
            vDec = Right(allt(str(genClave,10,2)), 2)
            finClave = vRound+vDec
            Thisform.txtPass.value = Rand(971);
    Exit
    Endif
Next y
产出:

vcad = 1 return: 99905 vcad = 2 return: 10077 vcad = thanks return: 17200
太棒了

相当于

Rand(vcad)
x = Rand(seedValue)
y = Rand()

相当于

Rand(vcad)
x = Rand(seedValue)
y = Rand()

但是,如果这些等价语句在VFP中产生与C.NET一样的结果,那么您应该认为自己非常幸运。底层实现必须是相同的,这会让我大吃一惊。如果它们不能产生相同的结果,而这是您的一项要求,那么您的任务就是找出FoxPro的Rand函数的内部实现是什么,并在c代码中复制它


如果vcad的值范围被限制在某个范围内,最简单的解决方案是使用VFP生成一个查找值表,并在c转换中使用它。

您的解决方案实际上可以像c.net 4.0中现有的两个方法一样简单

public int MyRandomFunction(string seedString)
{
    int hashCode = seedString.GetHashCode(); // Always returns the same integer based on a string
    Random myGenerator = new Random(hasCode);
    return myGenerator.Next(10000, 99999); // Returns a number between 10000 and 99999, ie 5 digits
}

您将始终获得相同的初始值,因为您总是从同一个种子开始。

正如我在您的另一个问题中所发布的那样,.net的VFP工具包可能具有相同的rand生成器函数

将VFP rand调用封装在COM dll中,并从.net调用它(如果您确实需要获得与所述完全相同的行为)


这似乎是一个奇怪的设计,但我想这是您的传统系统。

我需要在Rand FoxPro和C两种方法中获得相同的结果。netAt至少要勾勒出您的问题,并展示您的尝试。Stackoverflow并不是一个到处都是提供代码转换服务的金色小妖精的地方。尝试一个代码转换器。看看这个类-它有任何适用的Randint方法吗?我不知道VFP中的Randint语义是什么。工具箱的自复制的虚拟重新发布确实定义了Rand函数。它只调用普通的c Random.Next函数。这似乎是用户代码中的一个设计缺陷,它依赖于任何API实现的随机数生成来在所有未来版本中返回相同的序列。如hatchet Rand function Visual Fox Pro Toolkit所述。NET定义:public static double Random int nSeed{R=new System.Random System.Random nSeed;R.Next return;}如果VFP 6中的nSeed=971,此方法在C中返回0.70,此方法返回2627119处理方法Random.NextDouble nSeed返回0.0012234761202029,则无法复制此方法或将库导入到。net我最后的办法是使用一个接受参数的应用程序,但不要在Visual Fox Pro 6中这样做,所以我在这里结束这项研究,感谢C和VFP中的随机方法是不等效的,需要一个应用程序​​在VFP中,我们可以得到相同的结果。