天道酬勤,学无止境

random-time-generation

java:随机时间生成器(java: Random Time generator)

问题 如何生成随机Time值? 例如: 07:02:33 、 08:52:14等。我知道如何生成随机数,但我不知道如何执行此操作。 我想用随机值填充我的数据库列TIME 。 回答1 import java.util.Random; import java.sql.Time; final Random random = new Random(); final int millisInDay = 24*60*60*1000; Time time = new Time((long)random.nextInt(millisInDay)); 对于您的目的,这可能就足够了。 不要忘记,有些日子的长度不同,您可能需要为其添加测试用例(夏令时和闰秒)。 回答2 java.util.Date只是一个长值(自纪元以来的毫秒数)的包装器。 因此,您可以简单地使用Random.nextLong()生成随机长值,并将结果包装在new Date(result) 。 您可以将这些日期实例传递给您的 JDBC 驱动程序。 回答3 在,java1.8 Random generator = new Random(seed); LocalTime time = LocalTime.MIN.plusSeconds(generator.nextLong()); 回答4 使用 Random Generator 就像这里的

2021-08-31 14:31:13    分类:技术分享    java   random   time   random-time-generation

java: Random Time generator

How do I generate random Time values? For example: 07:02:33, 08:52:14, etc. I know how to generate random numbers but I don't know how to do this. I want to fill my database column TIME with random values.

2021-08-30 07:22:11    分类:问答    java   random   time   random-time-generation

用于上午 7 点至上午 11 点之间的时间的随机时间发生器 [关闭](Random Time Generator for time betweeen 7AM to 11AM [closed])

问题 很难说出这里问的是什么。 这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。 如需帮助澄清此问题以便重新打开它,请访问帮助中心。 8 年前关闭。 我正在创建一个测试文件,我需要在上午 7 点到上午 11 点之间用随机时间填充它。 重复输入是可以的,只要它们不完全相同 我也只对 HH:MM 感兴趣(没有秒) 我不知道从哪里开始。 发帖前我用谷歌搜索,发现一个有趣的搜索结果 www.random.org/clock-times/ 唯一的问题是所有“随机”生成的时间都是按顺序排列的。 我可以把它弄乱一次,但我需要生成 100 到 10,000 个条目。 我希望创建一个 WinForm C# 应用程序来帮助我做到这一点。 回答1 计算开始时间和停止时间之间的分钟数,然后生成一个介于 0 和最大分钟数之间的随机数: Random random = new Random(); TimeSpan start = TimeSpan.FromHours(7); TimeSpan end = TimeSpan.FromHours(11); int maxMinutes = (int)((end - start).TotalMinutes); for (int i = 0; i < 100; ++i) { int minutes = random.Next

2021-07-10 18:56:38    分类:技术分享    c#   winforms   random-time-generation

Random Time Generator for time betweeen 7AM to 11AM [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago. I am creating a test file and I need to fill it with random times between 7AM to 11AM. Repeating entries are OK as long as they aren't all the same I'm also only interested in HH:MM (no seconds) I don't know where to start. I did Google before posting and I found an interesting search result www.random.org/clock

2021-06-02 15:39:41    分类:问答    c#   winforms   random-time-generation

在固定间隔内产生明显的随机时间(Distinct random time generation in the fixed interval)

问题 我试图产生8:00 AM至8:00 PM为从数据集合中选择每行之间的随机时间,但是,我总是得到相同的随机值的每一行-我想这是针对不同每行。 表架构和数据: ╔══════╦════════════════╗ ║ ID ║ CREATED_DATE ║ ╠══════╬════════════════╣ ║ ID/1 ║ 26/04/2014 ║ ║ ID/2 ║ 26/04/2014 ║ ║ ID/3 ║ 26/04/2014 ║ ║ ID/4 ║ 26/04/2014 ║ ║ ID/5 ║ 26/04/2014 ║ ╚══════╩════════════════╝ urrent SQL语句: SELECT [ID] , MyFunction.dbo.AddWorkDays(14, [CREATED_DATE]) AS [New Date] , CONVERT(VARCHAR, DATEADD(MILLISECOND, CAST(43200000 * RAND() AS INT), CONVERT(TIME, '08:00')), 114) AS [New Time] FROM [RandomTable] 当前结果( [New Time]列中的每一行相同的时间): ╔══════╦════════════════╦════════════════╗ ║ ID ║ New

2021-05-06 10:45:05    分类:技术分享    sql   sql-server   sql-server-2008   tsql   random-time-generation

Distinct random time generation in the fixed interval

I'm trying to generate a random time between 8:00 AM and 8:00 PM for each row that is selected from a data set, however, I always get the same random value for each row – I want it to be different for each row. Table schema & data: ╔══════╦════════════════╗ ║ ID ║ CREATED_DATE ║ ╠══════╬════════════════╣ ║ ID/1 ║ 26/04/2014 ║ ║ ID/2 ║ 26/04/2014 ║ ║ ID/3 ║ 26/04/2014 ║ ║ ID/4 ║ 26/04/2014 ║ ║ ID/5 ║ 26/04/2014 ║ ╚══════╩════════════════╝ Сurrent SQL statement: SELECT [ID] , MyFunction.dbo.AddWorkDays(14, [CREATED_DATE]) AS [New Date] , CONVERT(VARCHAR, DATEADD(MILLISECOND, CAST(43200000 * RAND

2021-04-06 14:57:02    分类:问答    sql   sql-server   sql-server-2008   tsql   random-time-generation