vendredi 14 juillet 2017

VB6 Math.Random to C# Code

So I have the following code in VB6

string CharString = "KO0LPBGt7HU8NJI9acfDXESvgbYujmikolpw3MZWAQyhn6TFCR1q2Vzse4xdr5";

string DatePassword = string.Empty; 

float x = VBMath.Rnd(-1);
DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

x = VBMath.Rnd(-1);
VBMath.Randomize(dt.ToOADate());

for (int i=0; i<6; i++)
{
   double y = Math.Truncate(VBMath.Rnd()*62);
   DatePassword += CharString.Substring( Convert.ToInt32(y), 1);
}

I am having trouble converting this code over to C#. In particular how call randomize with the seed being a double. Here is my attempt in C#

string CharString = "KO0LPBGt7HU8NJI9acfDXESvgbYujmikolpw3MZWAQyhn6TFCR1q2Vzse4xdr5";

string DatePassword = string.Empty;

Random rnd = new Random(-1);
float x = rnd.Next();

DateTime dt = new DateTime(DateTime.Now.Year + DateTime.Now.Month + 1);

x = rnd.Next();
double z = rnd.NextDouble() * dt.ToOADate();

for (int i = 0; i < 6; i++)
{
    x = rnd.Next();
    double y = Math.Truncate(x * 62);
    DatePassword += CharString.Substring(Convert.ToInt32(y), 1);
}




Aucun commentaire:

Enregistrer un commentaire