VB.net随机发生器 [英] VB.net Random Generator

查看:103
本文介绍了VB.net随机发生器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是VB.net的新手,但是对于一个学校项目,我需要制作一个应用程序(游戏),因此我们决定在VB.Net中制作它.该游戏旨在向学生展示医院手术室的复杂性"计划.

我的问题是.我有一个随机类型的microsoft.access中3种类型的操作的列表(数据库).此列表包含3列:ID,代码和说明.现在,我希望VB.net在特定的一天从列表中随机生成X笔操作.这样,用户将看到例如必须计划到手术室旋转装置中的14项操作.我已经在VB.net中做了一些事情,但主要是图形方面的东西(其背后没有太多代码)..

如果有人能够逐步解释我,我将非常感激,因为我在VB.net中是完整的newb

Greetz,

Hello,

I''m new in VB.net but for a school project I need to make an application (game) so we decided to make it in VB.Net. The game is about showing students the planning ''complexity'' of a operation room in a hospital.

My question is. I have a list (database) of 3 types operations in microsoft.access from a random year. This list has 3 columns: I.D, Code and a description. Now I want VB.net to random generate a X amount of operations from the list for a specific day. That way the user will see for example 14 operations which has to be planned into the operation room rota. I already made some things in VB.net but mostly graphics stuff (not much coding behind it)..

I would be extremely thankful if some1 could explain me this step by step, because I''m complete newb in VB.net

Greetz,

推荐答案

尝试以下方法:
Try this one :
Private Function generateRandomCombination() As String
  Dim alphabet As String = "abcdefghijklmnopqrstuvwxyz"
  Dim randomNumber As New Random    
  Dim output As String = ""    
  For x As Integer = 1 To 25        
     If CBool(randomNumber.Next(0, 2)) Then
            output &= randomNumber.Next(0, 10).ToString  
     Else            
            output &= alphabet.Substring(randomNumber.Next(0, 26), 1).ToUpper    
     End If    
  Next    
  For x As Integer = 1 To 4        
     If x = 1 Then            
         output = output.Insert(x * 5, "-")        
     Else            
         output = output.Insert(x * 5 + x - 1, "-")        
     End If    
  Next     
  Return output 
End Function 


检查以下代码会产生1到40之间的随机数
check the following code it will generate random numbers between 1 to 40
Dim RandomClass As New Random()
RandomNumber = RandomClass.Next(1, 40)


这篇关于VB.net随机发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆