c# - there is any way to match the method RAND(INT) of Visual Fox Pro and C #. Net -


i'm migrating visual fox pro code c #. net

what makes visual fox pro: generates string of 5 digits ("48963") based on text string (captured in textbox), if enter same text string string 5 digits (no reverse), code in c #. net should generate same string.

there code can not play in dot.net rand (int)

in visualfoxpro:

rand(intvalue) 

in c #. net:

random r = new random (); return r.next(intvalue); 

in c# can´t generate single value based on same intvalue know different libraries (vfp , c #) not if there way match method of visual fox pro , c #. net

i want migrate following code (visual fox pro 6 c#)

gnlower = 1000 gnupper = 100000 vcad = 1 y=gnlower 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 

outputs:

vcad = 1 return: 99905 vcad = 2 return: 10077 vcad = return: 17200 

thks!

rand in .net not guaranteed same between major revision numbers, rand() seed of 1234 in 2.0 can different rand() in 4.0 exact same seed.

if must match old implientation need find out how visual fox pro did rand function. however, if want same behavior, not same numbers can hash string output that.

random r = new random (mytextbox.text.gethashcode());  return r.next(); 

now not cryptographically secure , not guaranteed generate same number on different computers (it returns different numbers between 32 , 64 bit, , different versions based on .net run-time (this applies both gethashcode , random itself!)), don't store database!


if need same number out every time same string in no matter computer on use rngcryptoserviceprovider in system.security.cryptography namespace.

//returns same number between 0 , 255 every time. using(var myrng = new rngcryptoserviceprovider(mytextbox.text)) {     var ret = new byte[1];     myrng.getbytes(ret);     return ret[0]; } 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -