-3

occupy a method made ​​in migrating Visual Fox Pro emigrarlo to C #, the problem I have is how to know if the method in Visual Fox Pro:

Rand(intValue)

method is equal to dotNet:

Random r = new Random (intValue);
r.Next return ();

assuming that intValue = 971 the result generated in dotNET is 2027119, but I need to be equal to that return FoxPro.

Primary question: how I can make sure I get the same result?

Secondary question: Do you know of any online tool fox pro to prove that this method gives me result Rand ()?

ch2o
  • 815
  • 2
  • 12
  • 29
  • 1
    so, you want to know if calling the Rand function in FoxPro will return the same value as calling Random.Next() in .NET? I guess that depends on whether the underlying algorithm is the same, which I doubt. – RobertMS Jun 05 '12 at 21:54
  • 1
    So you want two "random" numbers to not be random? Does not compute.. – Brad Cunningham Jun 05 '12 at 22:42
  • RobertMS: I also doubt that they have the same result. as I have no idea how to produce the same result in C # and FoxPro so I can think illustrate my problem – ch2o Jun 06 '12 at 00:55
  • Why do you continue to post the same question over and over?([link](http://stackoverflow.com/questions/10903014/there-is-any-way-to-match-the-method-randint-of-visual-fox-pro-and-c-net) and [link](http://stackoverflow.com/questions/10905171/migrate-method-randint-visual-fox-pro-to-c-net)) – Francesco Baruchelli Jun 06 '12 at 06:10
  • Self-duplicate of [there is any way to match the method RAND(INT) of Visual Fox Pro and C #. Net](https://stackoverflow.com/questions/10903014/there-is-any-way-to-match-the-method-randint-of-visual-fox-pro-and-c-net) – TylerH Mar 26 '20 at 15:22

5 Answers5

5

Primary question: how I can make sure I get the same result?

So you want to guarantee that you get the same result... from two different random number generators... right.

intValue in your FoxPro example is a seed value. Why in the world would you need to guarantee that the two libraries use the same random number generator (HINT: They almost certainly do not). Seriously, if you are after random numbers, what difference does it make?

If you want a known series of numbers then you really don't want a random number at all. This boggles my mind. If your code is setup to expect a certain string of values from a random number generator then there is a bigger problem. You may as well just generate a map using the numbers from FoxPro and get the numbers from there.

Ed S.
  • 122,712
  • 22
  • 185
  • 265
  • I do not want to get the same result with the same code, I want to get the same result in C # and Visual Fox Pro may be with the same method and / or any parameter or a different method. – ch2o Jun 06 '12 at 00:51
  • code is configured to expect a certain chain of values ​​if any value happens to the user, not describe the algorithm to not go into detail and answer me something else, as the user can capture any string I can not map thousands (or millions) of possible combinations generated by foxpro – ch2o Jun 06 '12 at 00:52
3

The only way you will achieve this is create a Visual FoxPro COM object with a method that takes a seed value and returns the random number generated, then use that via COM Interop in C#.

There is NO WAY TO MAKE NATIVE C# DO THIS. So stop asking.

Alan B
  • 4,086
  • 24
  • 33
2

I'm not sure why you would want to do that but here is a Visual FoxPro Toolkit for .NET http://foxcentral.net/microsoft/vfptoolkitnet.htm its possible it might have the same rand generator function.

Jay
  • 303
  • 1
  • 3
  • I do not want to depend on the application in visual fox pro, I want to be independent, your answer is what I have gained more hacerta for now, tomorrow will prove it .. thanks =D – ch2o Jun 06 '12 at 01:02
  • 1
    It just calls the normal c# Random.Next function ='( – ch2o Jun 06 '12 at 15:09
2

What you ask IS possible. You just can't use the generators provided to you by Foxpro and the .NET framework.

Most "random" number generators just generate sequence of numbers that "look" or "feel" random. They work like this (very simplified): Start with a "seed" value, apply a transform and generate a value, then apply the transform to this value and get next. Repeat as needed. The transform is such that you can expect the values to be uniformly distributed within a given segment, usually [0,1). I can explain this further, but there is plenty of literature around. Search for it.

Now, obviously, if you provide any given generator with the same seed, you will get the same sequence over and over again.

So, to obtain the result you want, you need to implement your own pseudo-random number generator in both VFP and C#. Keep in mind that there are things like difference in precision that could make successive calls to the generator, diverge.

Anyway, you will need an algorithm. Go here: use of D.Knuth pseudo-random generator

Hope this is still useful.

Community
  • 1
  • 1
FFiloseta
  • 33
  • 7
1

You can't. You are setting a seed value, but the chance that .NET and FoxPro is using exactly the same method to generate Random numbers is close to zero. But question is, why would you want this? Random is supposed to be random.

Quintium
  • 499
  • 5
  • 22
  • the code in visual fox pro did so, many use application and expect returns that result vfp – ch2o Jun 06 '12 at 00:59
  • It's because the random generaton in VFP is weak, so same seed returns the same result each time. Which makes it less random for a random generator. Only way you can get the same result in C# is by using a COM build in VFP (as @AlanB suggested) that uses the VFP random generator. – Quintium Jun 06 '12 at 13:19