1. And, if you want a more "random" seed, if RDRAND is not available, you can change SRAND_() like this:
Code:
```static void SRAND_(void)
{
int fd;
unsigned int rnd;
ssize_t size;

if ( ( fd = open( "/dev/urandom", O_RDONLY ) ) < 0 )
{
perror("open");
goto fallback;
}

if ( ( size = read( fd, &rnd, sizeof rnd ) ) != sizeof rnd )
{
if ( size < 0 )
close( fd );
goto fallback;
}

close(fd);

srand( rnd );

return;

fallback:
// In case of failure, use the timestamp anyway...
srand( time( NULL ) );
}```
Of course, all this only works on "unix"...

2. Thanks you for all your comments but when I typed select 6 numbers I meant that you use the scanf function to input 6 numbers and to check if these are the winning or losing numbers.

3. In all your examples you used arrays,functions,outputs but they seem too complicated. Don't you have steps that are a lot easier than what you showed me?

4. Anyone?

6. pass

7. Well if you've never written any code, then all the exuberance shown by the regulars probably isn't what you want.

Here's an exercise for you.
- create an array of 49 elements, and use a loop to fill that array with the numbers 1 to 49.
Then print the array.

8. Originally Posted by Salem
Well if you've never written any code, then all the exuberance shown by the regulars probably isn't what you want.

Here's an exercise for you.
- create an array of 49 elements, and use a loop to fill that array with the numbers 1 to 49.
Then print the array.
It's my first time in programming and this is a partial code,it's not done:
int numbers[49];
for(i=1;i<=49;i++)
numbers[i]=i;

I don't know how to continue

9. Right, first issue is that arrays start at subscript 0.

for ( i = 0 ; i < 49 ; i++ )

Then I asked you to print the array.
Which would be the same kind of loop, and a printf() statement.

10. Originally Posted by Salem
Right, first issue is that arrays start at subscript 0.

for ( i = 0 ; i < 49 ; i++ )
But you specified that I should be doing 49 elements and not 50. Am I not correct?

11. Code:
```int numbers[49];
for ( int = 0 ; i < 49 ; i++ ) numbers[i] = i+1;```
vs this, which wastes element 0 of the array.
Code:
```int numbers[50];
for ( int = 1 ; i <= 49 ; i++ ) numbers[i] = i;```
Which, if you replaced <=49 with <50, would be identical to
Code:
```int numbers[50];
for ( int = 1 ; i < 50 ; i++ ) numbers[i] = i;```
The idiomatic for loop used < N as the end condition, where N is the dimension of the array subscript being looped over.

12. Code:
```#include<stdio.h>
int main() {
int a[6],v[6];
srand(time(0));
int ok=1;
for(int j=1;j<=6;j++){
int n= 1+(rand()%49);
int v[j] = n;
}
for(int i=1;i<6;i++)
for(int j= i+1;j<=6;j++)
if(v[i]==v[j])
v[j]=(1+(rand()%49)+2)/2;
for(int j=1;j<=6;j++)
scanf("a[%d]",&a[j]);
for(int i=1;i<6;i++)
for(int j=i+1; j<=6; j++)
if(a[i]==a[j])ok=2;
for(int i=1; i<=6; i++)
{if(a[i]>49||a[i]<1||ok==2)
printf("Inappropriate list for Lottery!");
ok=0;
break;
}
if(ok==1){
for(int i=1; i<=6; i++)
{if(i==1)
printf("Inappropriate list for Lottery!");
ok=0;
break;}}
if(ok==1){
for(int i=1; i<=6; i++)
{if(i==1)
if(a[i]<=49&&a[i]>=1)
printf("a[i]");
printf("Winning numbers this time : %d \n");
for(int i=1;i<=6;i++)
printf("v[i]");
int nr=0;
for(int i=1;i<=6;i++)
for(int j=1; j<=6; j++)
if(a[i]==v[j])nr++;
int jk=0;if(nr==6)jk=1;
if(jk==0){
printf("You hit %d numbers");
printf("You have (nr*100)/6 chances to win");
}
else{
printf("YOU GOT THE JACKPOT");
}
return 0;
}```
I tried to convert the c++ code in the c code and I want to know if what I wrote here is correct or there are some errors which I have to change. The code is indeed complicated but since this is the only thing I found...

13. Originally Posted by wolly
I tried to convert the c++ code in the c code and I want to know if what I wrote here is correct or there are some errors which I have to change. The code is indeed complicated but since this is the only thing I found...
The code desperately needs to be formatted properly and use descriptive variable names where appropriate, and possibly broken up into smaller functions that do one thing and do it well.

But more importantly, the point is to understand and learn, not to blindly convert code from one programming language to another: if that is all you want to do, then forget it as I shall replace you with a program because you're nothing more than a compiler, and even less than a compiler because you most certainly cannot perform routine optimisations. "Blindly convert code from one programming language to another" isn't even a transferable skill that might come in handy outside of software: you're better off learning a second natural language + translation skills: at least you'll be able to find a job as a translator, even in a world where machine translation of human languages is approaching human standards.

My suggestion is this: come up with an algorithm and describe it to us (e.g., in pseudocode, or even in prose). You can then get feedback as to whether the algorithm is feasible or needs fixing. After that, implement your algorithm, and test it,then you can post here again as for feedback on your code.

14. > The code is indeed complicated but since this is the only thing I found...
So it looks like wolly isn't interested in learning after all.

If you're serious, start doing the mini exercise I posted a couple of days ago.
It will lead to the answer eventually, and it might actually TEACH you a useful skill or two along the way.

15. Thank you for the help,@Salem. I'm a bit confused about what you said with arrays
For example if I would create an array like this and I refuse to use the for loop would that be a problem?
Code:
``` int lotto[49] =
{
1,  2,  3,  4,  5,  6,  7,
8,  9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42,
43, 44, 45, 46, 47, 48, 49
}```
When I try to increase the array's element lotto[i] = i+1 I don't get 48 or 49 numbers situated in a column and what I get is the number 42 with no reason at all.