Your technology certification is waiting. Enroll in Cloud Class ®
Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
private Random random = new Random();
private TimeSpan RandomHours(double minHour, double maxHour)
return TimeSpan.FromMilliseconds(TimeSpan.FromHours(minHour).TotalMilliseconds + (random.NextDouble() * TimeSpan.FromHours(maxHour - minHour).TotalMilliseconds));
private void button1_Click(object sender, EventArgs e)
DateTime dt = DateTime.Now.Add(RandomHours(.5, 10));
Open in new window
public virtual int Next(
public partial class Form1 : Form
static Random rand = new Random();
timer1.Interval = rand.Next(30, 600) * 60000; // 30 - 600 minutes (.5 - 10 hours) times 60000 to get millisecs
To produce random integers in a given range, use this formula:
Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.