Of 7 random numbers it's happening that some of these numbers are the same.
I tryed to use do-while loop to fix this, but problem still consist.
Here is the code: - input:
-
enum bool {FALSE,TRUE};
-
unsigned int a[BR_BROJ],b[BR_BROJ],p[BR_BROJ],q[BR_BROJ];
-
int x,y,k,i,j,L,kk,xi,yi;
-
int e,w;
-
int br,m=0;
-
-
for(i=0;i<BR_BROJ;i++) a[i]=b[i]=p[i]=q[i]=0;
-
textbackground(7);
-
textcolor(4);
-
clrscr();
-
do{
-
randomize();
-
for(i=0;i<BR_BROJ;i++) a[i]=random(39)+1;
-
-
}while((a[1]==a[2]||a[1]==a[3]||a[1]==a[4]||a[1]==a[5]||a[1]==a[6]||a[1]==a[7])&&(a[2]==a[3]||a[2]==a[4]||a[2]==a[5]||a[2]==a[6]||a[2]==a[7])&&(a[3]==a[4]||a[3]==a[5]||a[3]==a[6]||a[3]==a[7])&&(a[4]==a[5]||a[4]==a[6]||a[4]==a[7])&&(a[5]==a[6]||a[5]==a[7])&&(a[6]==a[7]));
Please help.
5 1293
I think the problem may ber not so much that two numbers are the same, but rather that the while loop should only have or (||) and not and (&&)
Certainly some more parentheses would simplify the logic (and that seems a very tedious way to check....
It may be easier to :
1 loop through as you are now
2.1 choose a random number
2.2 check whether it's in the array here and regenerate if necessary
3 continue on
I think the problem may ber not so much that two numbers are the same, but rather that the while loop should only have or (||) and not and (&&)
Certainly some more parentheses would simplify the logic (and that seems a very tedious way to check....
It may be easier to :
1 loop through as you are now
2.1 choose a random number
2.2 check whether it's in the array here and regenerate if necessary
3 continue on
I tried that before and it looks like it does not help
Thanks for the help
I tried that before and it looks like it does not help
Thanks for the help
Which did you try? His first explanation, or his alternate decision?
Banfa 9,065
Expert Mod 8TB
Your while loop is completely failing to test a[0], however it is testing a[7] but you say only generate 7 numbers clearing starting from index 0 in the generating loop which suggests that a[7] is an out of bounds array access.
Your while loop is completely failing to test a[0], however it is testing a[7] but you say only generate 7 numbers clearing starting from index 0 in the generating loop which suggests that a[7] is an out of bounds array access.
Uhm, I see thanks for the help.
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: Blake T. Garretson |
last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to
disk in a secure manner in one of my programs. What is the
easiest/best way to accomplish strong file encryption in Python? ...
|
by: Virus |
last post by:
Ok well what I am trying to do is have
1.) the background color to change randomly with 5 different colors.(change
on page load)
2,) 10 different quotes randomly fadeing in and out in random...
|
by: Leon |
last post by:
I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.
Do anybody know of any good books or websites that explain how to generator
random...
|
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...
|
by: Alvin |
last post by:
Well, I'm developing a Tetris game in SDL, but when it comes to
deciding the next block, I'm stuck. It's random, but when I try
something like seeding the randomizer with the time, it won't update...
|
by: Karlo Lozovina |
last post by:
Here is it:
---
class Human:
def __init__(self, eye_one, eye_two):
self.eye_one = eye_one
self.eye_two = eye_two
class Population:
def __init__(self):
|
by: TreatmentPlant |
last post by:
I need to generate a few thousand true random numbers using C++.
I have some code now that does alright, but when you plot the results on
a graph, you notice patterns, so the numbers are not...
|
by: Ethan Strauss |
last post by:
Hi,
There have been quite a few discussions of Random not giving random
numbers and how to fix that by feeding in a new seed each time, waiting
enough time, or calling the Next() method of the...
|
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 ...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |