473,837 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array random re-created mantains the same values

Pao
My code works in this way:
I declared a static array in a class (public static int[] GVetRandom =
new int[3];)
that in a for cycle I fill with random numbers.
The array gets cleared (clear method) and refilled at each turn of
cycle.

On my developing pc, the same sequence of random numbers was repeated
from on turn of cycle to the other; I put some Application.DoE vents()
and all gone well.

But in the customer's pc, the array are generated exactly the same
yet, it gives 2 or 3 duplicates
for example:
1st turn in teh for: the array is 10-56-33
2nd turn in teh for: the array is 34-22-54
3rd turn in teh for: the array is 34-22-54
4th turn in teh for: the array is 34-22-54
5th turn in teh for: the array is 65-31-24

what could it be???

Dec 15 '06 #1
6 2126
Pao wrote:
But in the customer's pc, the array are generated exactly the same
yet, it gives 2 or 3 duplicates
for example:
1st turn in teh for: the array is 10-56-33
2nd turn in teh for: the array is 34-22-54
3rd turn in teh for: the array is 34-22-54
4th turn in teh for: the array is 34-22-54
5th turn in teh for: the array is 65-31-24

what could it be???
Dunno. Why don't you post an actual code snippet?

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
Dec 15 '06 #2
Pao wrote:
My code works in this way:
I declared a static array in a class (public static int[] GVetRandom =
new int[3];)
that in a for cycle I fill with random numbers.
The array gets cleared (clear method) and refilled at each turn of
cycle.

On my developing pc, the same sequence of random numbers was repeated
from on turn of cycle to the other; I put some Application.DoE vents()
and all gone well.

But in the customer's pc, the array are generated exactly the same
yet, it gives 2 or 3 duplicates
for example:
1st turn in teh for: the array is 10-56-33
2nd turn in teh for: the array is 34-22-54
3rd turn in teh for: the array is 34-22-54
4th turn in teh for: the array is 34-22-54
5th turn in teh for: the array is 65-31-24

what could it be???
What are you using as the seed for your random numbers? A guess is that
possibl you are using a date or time that isn't precise enough. A random
number generator with the same seed will produce the same "random" numbers.
Take a look at the following examples:

// this will produce the same results several times through the loop
for (int h = 0; h < 100; h++)
{
DateTime now = DateTime.Now;
int seed = now.Second * 1000 + now.Millisecond ;
Random random = new Random(seed);
int[] rand = new int[3];
for (int i = 0; i < rand.Length; i++)
{
rand[i] = random.Next(0, 100);
}
Console.WriteLi ne("{0}-{1}-{2}", rand[0], rand[1], rand[2]);
}

// this will be much more random than the first example
DateTime now = DateTime.Now;
int seed = now.Second * 1000 + now.Millisecond ;
Random random = new Random(seed);
for (int h = 0; h < 100; h++)
{
int[] rand = new int[3];
for (int i = 0; i < rand.Length; i++)
{
rand[i] = random.Next(0, 100);
}
Console.WriteLi ne("{0}-{1}-{2}", rand[0], rand[1], rand[2]);
}
If that's not it, if you post a sample code that reproduces the problem, no
doubt someone can point out the cause.
--
Tom Porterfield

Dec 15 '06 #3
Hi,

I'd like to wager a guess that you're recreating a new Random object each
time the array is generated. Instead, keep a single read-only instance of a
Random object in a field and use that each time.

--
Dave Sexton

"Jon Shemitz" <jo*@midnightbe ach.comwrote in message
news:45******** *******@midnigh tbeach.com...
Pao wrote:
>But in the customer's pc, the array are generated exactly the same
yet, it gives 2 or 3 duplicates
for example:
1st turn in teh for: the array is 10-56-33
2nd turn in teh for: the array is 34-22-54
3rd turn in teh for: the array is 34-22-54
4th turn in teh for: the array is 34-22-54
5th turn in teh for: the array is 65-31-24

what could it be???

Dunno. Why don't you post an actual code snippet?

--

.NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.

Dec 15 '06 #4

Don't don't instantiate a random number generator each tiem through
the loop--create one once and reuse that throughout the lifetime of
the application.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On 15 Dec 2006 11:57:59 -0800, "Pao" <pa********@gma il.comwrote:
>My code works in this way:
I declared a static array in a class (public static int[] GVetRandom =
new int[3];)
that in a for cycle I fill with random numbers.
The array gets cleared (clear method) and refilled at each turn of
cycle.

On my developing pc, the same sequence of random numbers was repeated
from on turn of cycle to the other; I put some Application.DoE vents()
and all gone well.

But in the customer's pc, the array are generated exactly the same
yet, it gives 2 or 3 duplicates
for example:
1st turn in teh for: the array is 10-56-33
2nd turn in teh for: the array is 34-22-54
3rd turn in teh for: the array is 34-22-54
4th turn in teh for: the array is 34-22-54
5th turn in teh for: the array is 65-31-24

what could it be???
Dec 15 '06 #5
Pao

Dave Sexton and Samuel R.Neff wrote:
>Don't don't instantiate a random number generator each tiem through
the loop--create one once and reuse that throughout the lifetime of
the application.

Thank you all very much, expecially Dave and Samuel.
I tried their suggestion above and all works now.

Dec 16 '06 #6

I want to know what is some RSA security's product using as the seed
for its random numbers or how I can find their product's
whitepaper----if it does exist.
My object is to find some ways of producing random numbers.
I will appreciate you if you send somethings om that tome.
My email:sk******* **@gmail.com

Dec 21 '06 #7

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

Similar topics

4
25569
by: pablo | last post by:
Dear News Groupers, I'am trying to send a php array with a hidden input field from a form to another script. The array is NOT made directly by way of <input name="arrayname" />. The array is made by normal php code and then submitted between form-tags as echo "<input type='hidden' name=\"arrayname\" value=\"$arrayname\" />" ;
15
3342
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI layer. EG. bits-layer 1. Any way, I want the quiz to reorder the problems each time I take it. Here is part of the code i did so far for 62 components in the quiz.
2
928
by: Anil | last post by:
Hi All, I have a string which has product names, which are seperated by comma. The number of products in the string are random. I want to populate the array using the string, one product per level. Please let me know how to do it. Thanks in Advance, Anil
4
2722
by: James | last post by:
Just learning C#. What's the easiest way to assign numbers 1-10 randomly to an array? Basically I just want to take the numbers 1-10 and arrange them randomly in slots 0-9 of an array. Thanks
9
28849
by: gl | last post by:
How do I take an array or arraylist, and sort it randomly? Like suppose the items in it are (1,2,3,4,5) and I want to get it to be in a random order (2,3,1,4,5). How do you do that? I think it's a call to the array or array lists sort method, but i'm not exactly sure how you do it.
6
7866
by: Paul van Brenk | last post by:
When you run the Shuffle method often enough it will throw exception. And I can't figure out why. Anybody? Paul van Brenk the code: static void Shuffle(){ int ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
5
2087
by: jar13861 | last post by:
I'm confused on how to write a random array that will only generate 9 different numbers from 1-9. Here is what I have, but its only writing one number.... holder = new Array ( 9 ); var flag = true; var rannum = Math.floor( 1 + Math.random() * 9 ); for (var j = 0; j < 9; j++) {
5
6524
by: John | last post by:
How can I fill an array randomly so it contains a certian range of numbers (1 - 100 for example) ? My Goal is to generate a set of numbers in random order.
9
4418
by: JuAn2226 | last post by:
HI I'M NEW IN VB6. i HAVE PROJECT WHICH REQUIRES ME TO STORE RANDOM NUM IN ARRAY N CAPTURE TIME FOR EACH OF THE NEW NUM IN THE ARRAY FORM. Actually my project is to calculate the average car speed. I have to code in vb for real-time application. for example i have to developed 10 array with name of the array is CarID.Each time a car passes the road the rfid reader will ditact the carID and store it in the array together the time the car reach...
4
1534
by: kidko | last post by:
I'm writing a small game in Javascript (using just PNGs for graphics and DOM manipulation to move them), and most of the content is procedurally generated. This includes all of the weapons involved, and this is where the problem lies. The problem lies somewhere in here, I believe: function Weapon(weaponName, weaponDamage, weaponAccuracy, weaponAmmo, weaponRate, weaponClip) { /* === Weapon Structure === * weapon.nm - The weapon's name *...
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10886
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10580
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10277
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4479
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.