Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,561 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,899 people online right now. Registration is fast and FREE... Join Now!




How do i get non-psuedo random number gen. in VB.net

 
Reply to this topicStart new topic

How do i get non-psuedo random number gen. in VB.net, VB 03

Jmaxx
9 Apr, 2008 - 02:43 PM
Post #1

New D.I.C Head
*

Joined: 9 Apr, 2008
Posts: 1

I'm not going to post the entire 500+ lines.

What we are doing is making a battle ship game.
Our problem lies with the random number generator, there exists a pattern that is predictable.
We're wondering how to code a truly random number generator.

Heres the generator code we have:

vb

'Pick a random location for ship
Dim intShip As Integer = Int(Rnd() * 8)
Dim intMiss As Integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If intShip + 1 = 1 Then
picShip1.BringToFront()
MessageBox.Show("You hit the ship!", "Congratulations!")
If intMiss >= 5 Then
picLose.BringToFront()
Else
picWin.BringToFront()
End If
Else
intMiss = intMiss + 1
picMiss1.BringToFront()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If intShip + 1 = 2 Then
picShip2.BringToFront()
MessageBox.Show("You hit the ship!", "Congratulations!")
If intMiss >= 5 Then
picLose.BringToFront()
Else
picWin.BringToFront()
End If
Else
intMiss = intMiss + 1
picMiss2.BringToFront()
End If
End Sub

*edit: Please use code tags in the future, thanks! code.gif

This post has been edited by Martyr2: 9 Apr, 2008 - 03:00 PM
User is offlineProfile CardPM
+Quote Post

KG87
RE: How Do I Get Non-psuedo Random Number Gen. In VB.net
9 Apr, 2008 - 02:47 PM
Post #2

D.I.C Head
**

Joined: 25 Sep, 2007
Posts: 52



Thanked: 2 times
My Contributions
Sorry i can't help you on this, But i think your post will be moved, Since it's a .net Question

though one suggestion would be to populate a listbox with say 100 random numbers, then create a listbox1.listindex((rnd)... and select the number from there. umm, hope that helps crazy.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How Do I Get Non-psuedo Random Number Gen. In VB.net
9 Apr, 2008 - 03:16 PM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well first the only way to really get a non-pseudo random generator is to use a hardware generator. That is because anything generated by the computer is dependent on a seed value which you explicitly or implicitly set. The best way to do this would be to have the hardware generator generate the seed for a pseudo random number generator.

Now you could base your random number generator off something like the system time as the seed or you could come up with an algorithm shown to generate strong seeds for the generator.

Keep in mind that if you are going to use the Rnd() function you must call "Randomize()" first before otherwise you will get a predictable set of numbers each time the program is run. This could be part of your problem.

Since Rnd() and Randomize() are from the old VB 6 era, you might want to consider using the Random class which doesn't need this Randomize() called before and is more suited for the .NET environment.

Hope that helps. smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:37PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month