im new to this forum and wanted to kno how to create a random number generator that would pick between 1-7 ? in 3 different places thus creating a slot machine for my project in school.. please help
Random number generator?
Started by sjshacker93, Aug 19 2010 09:52 AM
5 replies to this topic
#1
Posted 19 August 2010 - 09:52 AM
|
|
|
#2
Posted 19 August 2010 - 01:01 PM
hey, i guess you will be using forms....
I dont feel comfortable giving the code but i can explain how it could be done if you would like...
if you want to me send me a private message with your msn address in it and i will explain to you
I dont feel comfortable giving the code but i can explain how it could be done if you would like...
if you want to me send me a private message with your msn address in it and i will explain to you
#3
Posted 19 August 2010 - 02:15 PM
Hey Alex3k since this is a help community based on helping people why not explain it here that way if someone happens across this site with the same question there's somewhere for them to start :)
#4
Posted 19 August 2010 - 03:39 PM
If you are using VB.NET then use Random class: rnd.Next() mod 7 - that will return uniformly distributed random numbers between 0 and 6 inclusive.
If you're using plain VB, then use Rnd function (I think that was the name). Make sure that Randomize function is invoked at the beginning of execution of the program. Again, use Rnd mod 7, which will return numbers between 0 and 6 inclusive.
Random number generators in both languages are based on Linear Congruential Generator (LCG). Note that LCG is used to generate quite large numbers, and then modulo 7 operation is used to reduce the result into the desired range. This method provides longer sequence of numbers before repetition. If you study that Wikipedia page carefully, you'll get to same conclusion.
Make sure that you never combine multiple results of LCG unless you are very sure what you're doing, which can be true only if you are strong in Probability and Statistics fields. For example, formula (LCG + LCG) mod 7 does not produce uniformly distributed values.
If you're using plain VB, then use Rnd function (I think that was the name). Make sure that Randomize function is invoked at the beginning of execution of the program. Again, use Rnd mod 7, which will return numbers between 0 and 6 inclusive.
Random number generators in both languages are based on Linear Congruential Generator (LCG). Note that LCG is used to generate quite large numbers, and then modulo 7 operation is used to reduce the result into the desired range. This method provides longer sequence of numbers before repetition. If you study that Wikipedia page carefully, you'll get to same conclusion.
Make sure that you never combine multiple results of LCG unless you are very sure what you're doing, which can be true only if you are strong in Probability and Statistics fields. For example, formula (LCG + LCG) mod 7 does not produce uniformly distributed values.
#5
Posted 20 August 2010 - 01:34 AM
Sorry guys, i was only suggesting MSN so i could send pictures...sorry...
i would do something like...
Dim RND as new random
Dim Random1 as integer
Dim Random2 as integer
Dim Random3 as integer
Random1 = rnd.next(0,8)
Random2 = rnd.next(0,8)
Random3 = rnd.next(0,8)
that is to get a general random, VSWE taught me to do something like that.
The (0,8) in the code means you set the bounds for the next.... it gets a number between 0 and 7.
Hope this helps,
i would do something like...
Dim RND as new random
Dim Random1 as integer
Dim Random2 as integer
Dim Random3 as integer
Random1 = rnd.next(0,8)
Random2 = rnd.next(0,8)
Random3 = rnd.next(0,8)
that is to get a general random, VSWE taught me to do something like that.
The (0,8) in the code means you set the bounds for the next.... it gets a number between 0 and 7.
Hope this helps,
#6
Posted 03 September 2010 - 08:27 PM
Alex3k said:
hey, i guess you will be using forms....
I dont feel comfortable giving the code but i can explain how it could be done if you would like...
if you want to me send me a private message with your msn address in it and i will explain to you
I dont feel comfortable giving the code but i can explain how it could be done if you would like...
if you want to me send me a private message with your msn address in it and i will explain to you
Hmm. I don't know VB (won't install) but i'd say you need to say something like:
Textbox1 = Random(1-7)
Thats not acutally code but its pretty close to what you need.
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).


Sign In
Create Account

Back to top









