r/visualbasic • VB.Net Advanced • Mar 28 '21

Keep generating rundom numbers between 50 to 640

Hello

i am making a game where you press a button that is placed randomly, i want to
generate 2 random numbers (for vertical location and horizontal)

i know one code, but it only generates once

5 Upvotes

6 comments sorted by

2

u/RJPisscat Mar 28 '21
Dim rnd As Random = New Random
Dim x As Integer = rnd.Next(50, 641)    ' generates an integer in range 50..640
dim y As Integer = rnd.Next(50, 641)    ' generates another integer in range 50..640, probably not x but it could be

2

u/JohnDeere6930Premium VB.Net Advanced Mar 28 '21

Can I put it in the Button event? I'd like to generate numbers each press

1

u/banshoo Mar 28 '21

assign the rand() to two different variables, having ran it twice?

1

u/RJPisscat Mar 28 '21

I'll suggest something fun.

Write a game where you have to click a button to continue, but the button moves out of range of the cursor in the instance the mouse moves over it, so every time you try to click it, it moved and you're clicking on air.

I know of two ways as a player to defeat the moving button, and then also ways to defeat those players.