473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Random numbers

GB
How can I create a random number in a set range without using the follwoing
code:

Randomize
Return cint(int((5*rnd()) + 0)

I am looking for something more random than the above as the result seem to
be predictable for small ranges.

Thanks,
Gary
Nov 20 '05 #1
9 1413
On Fri, 14 Nov 2003 11:41:33 -0800, GB wrote:
How can I create a random number in a set range without using the follwoing
code:


Dim iRandomNumber As Integer

'Initialize the random number generator with a seed based on the system
'clock
Dim rnd As New Random(Environment.TickCount)

'Gets a random number from 1 to 9999
iRandomNumber = rnd.Next(1,10000)

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #2
Hello, GB:

You have complete information in the System.Random class topic, including where to look for a stronger random number generator and how to easily generate a number within a range:
http://msdn.microsoft.com/library/?u...asp?frame=true

Regards.
"GB" <g@p.com> escribió en el mensaje news:uf**************@tk2msftngp13.phx.gbl...
| How can I create a random number in a set range without using the follwoing
| code:
|
| Randomize
| Return cint(int((5*rnd()) + 0)
|
| I am looking for something more random than the above as the result seem to
| be predictable for small ranges.
|
| Thanks,
| Gary
|
|
Nov 20 '05 #3
Hello, GB:

You have also complete information in the System.Random class topic (note this is not the same as Rnd), including where to look for a stronger random number generator and how to easily generate a number within a range:
http://msdn.microsoft.com/library/?u...asp?frame=true

Regards.
"GB" <g@p.com> escribió en el mensaje news:uf**************@tk2msftngp13.phx.gbl...
| How can I create a random number in a set range without using the follwoing
| code:
|
| Randomize
| Return cint(int((5*rnd()) + 0)
|
| I am looking for something more random than the above as the result seem to
| be predictable for small ranges.
|
| Thanks,
| Gary
|
|
Nov 20 '05 #4
* "GB" <g@p.com> scripsit:
How can I create a random number in a set range without using the follwoing
code:

Randomize
Return cint(int((5*rnd()) + 0)

I am looking for something more random than the above as the result seem to
be predictable for small ranges.


Have a look at the 'Random' class and its methods. Nevertheless, I
don't understand why the numbers generated by the pseudo-random number
generator should be easily predictable.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #5
On 14 Nov 2003 21:22:03 +0100, Herfried K. Wagner [MVP] wrote:
don't understand why the numbers generated by the pseudo-random number
generator should be easily predictable.


Perhaps he was starting with the same seed each time.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #6
* Chris Dunaway <dunawayc@_lunchmeat_sbcglobal.net> scripsit:
don't understand why the numbers generated by the pseudo-random number
generator should be easily predictable.


Perhaps he was starting with the same seed each time.


Mhm... He calls 'Randomize', that should be OK.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #7
>
Perhaps he was starting with the same seed each time.

Nope, he called Randomize first, unless of course his clock has stopped, in
which case he'll have the same problem with Random.
Nov 20 '05 #8
* "Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> scripsit:
Perhaps he was starting with the same seed each time.


Nope, he called Randomize first, unless of course his clock has stopped, in
which case he'll have the same problem with Random.


Maybe he run the code on different machines at exactly the same time?

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #9
The Randomize command initializes the random number generator with the
current system time. The problem is that the resolution (i.e. the
precision or granularity) of the system clock is limited. If you run the
code below in a tight loop, no clock ticks will have a chance to occur
between every two iterations.

The solution is to randomize just once at the start of the application.

GB wrote:
How can I create a random number in a set range without using the follwoing
code:

Randomize
Return cint(int((5*rnd()) + 0)

I am looking for something more random than the above as the result seem to
be predictable for small ranges.

Thanks,
Gary


Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Nicholas Geraldi | last post by:
Im looking for a decent random number generator. Im looking to make a large number of random numbers (100 or so, if not more) in a short period of time (as fast as possible). the function i was...
3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
5
by: cvnweb | last post by:
I am trying to generate 2 random numbers that are diffrent, in order to add them to existing numbers to generate numbers that start out the same, but are randomly added and subtracted so that they...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
6
by: badcrusher10 | last post by:
Hello. I'm having trouble figuring out what to do and how to do.. could someone explain to me what I need to do in order to work? THIS IS WHAT I NEED TO DO: Professor Snoop wants a program...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.