主谋 [英] MasterMind

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

问题描述

你好

我刚开始学习如何编写visual basic(.Net FrameWork)代码,我想知道如何在0000和9999之间创建一个随机数

I've just started learning how to code visual basic (.Net FrameWork) and i was wondering how can i create a random number between 0000 and 9999

我已尝试过4行代码  number = Int(Rnd()* 9998) 

i've tried things like number = Int(Rnd() * 9998) for 4 lines of code 

例如

dim X1 as new random 

dim X1 as new random 

x1 = Int(Rnd()* 9998) 

x1 = Int(Rnd() * 9998) 

我想要将其分为4个单独的数字,例如如果x1是9876,我希望它显示9,8,7,6,以便我可以看到我是否正确猜测一个数字,例如如果我的猜测是9772,它会说9是正确的,所以是7 

i then want to divide it into 4 seperate digits e.g. if x1 is 9876 i want it to show 9,8,7,6 so that i can see if im correct for guessing a number e.g. if my guess was 9772, it'd say 9 was correct and so was 7 

有没有办法在.Net  FrameWork中做到这一点?

Is there a way to do that in .Net FrameWork?

我目前的代码是这个

推荐答案

您好

随机数生成器比现在老Rnd方法。你声明一个新随机并在你的代码中使用/重用多次。

The Random number generator is much better than the old Rnd method now. You declare a New Random and use / reuse throughout your code as many times as needed.

如下所示,你定义所需的tange - 例如1000到10000,坚持记住,在方法中使用Max需要+1(这是一个
包含 / 独占类型对)

As below, you define the tange needed - such as 1000 to 10000, nut remember, in the method to use the Max needed +1 (it is an inclusive / exclusive type pair)

RANDOM

Option Strict On
Option Explicit On
Public Class Form1
	Dim rand As New Random
	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

		' find a new random number between
		'  1000 And 10000 NOTE second  
		'  parameter is max required +1
		Dim newnumber As Integer = rand.Next(1000, 10001)

	End Sub
End Class


这篇关于主谋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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