Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I asked for help I this portal because I don't know how to convert this line of Visual Basic code in C# that returns a random number even after some time to try to do this.

This I the vb Code:

VB
private int Random_number(int min, int max)
        {
            return (int)(Conversion.Int((max - min + 1) * VBMath.Rnd()) + min);
        }


I have try this:

C#
private int Random_number(int min, int max)
{
    int seed = DateTime.Now.Millisecond;
            Random rnd = new Random(seed);
            return rnd.Next(min, max);
}


but it don't works, and I don't know why. Can anyone help with it.

P.S. Did somebody have any Tabu Search implementation in Sudoku or any reference for it.
Thanks in advantage.
Posted
Comments
[no name] 17-Apr-13 16:37pm    
What on earth does "but it don't works" even mean?

Just Do it:

C#
private int Random_number(int min, int max)
        {

            Random rndCell = new Random((int)DateTime.Now.Millisecond);
            return rndCell.Next(min, max);
        }
 
Share this answer
 
 
Share this answer
 
You should not ask questions every time you need such translations. Here are a couple of much better possibilities:



Good luck,
—SA
 
Share this answer
 
v2
Try this:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            Program objPgrm = new Program();
           Console.WriteLine( objPgrm.Random_number(14, 100));
           Console.ReadLine();

        }

        private int Random_number(int min, int max)
        {
            int RndNO = new Random().Next(min, max);

            return ((max - min + 1) * RndNO  + min);
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900