Jak napisać kod aby program wybierał kilka losowych liczb z danego zbioru np 5 liczb ze zbioru od 1 do 50 i pokazywał? Ważnym jest aby te liczby sie nie powtarzały (to tak jak w totolotku).
Wyczarowałem cos takiego ale chyba nie jest to dobrze (nawet sie nie kompiluje):
Kod: Zaznacz cały
#include <vcl.h>
#pragma hdrstop
#include <iostream>
#include <ctime>
#include <conio.h>
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int a,b,c,d,e,f;
b!=a;
b!=c;
b!=d;
b!=e;
b!=f;
c!=a;
c!=e;
c!=b;
c!=d;
c!=f;
d!=a;
d!=b;
d!=c;
d!=e;
d!=f;
e!=a;
e!=b;
e!=c;
e!=d;
e!=f;
f!=a;
f!=b;
f!=c;
f!=d;
f!=e;
a=(rand()% 50);
b=(rand()% 50);
c=(rand()% 50);
d=(rand()% 50);
e=(rand()% 50);
f=(rand()% 50);
randomize();
srand(unsigned(time(0)));
for(a=0; a<50; a++);
Edit1->Text=((rand()% 50));
do
{rand()% 49;}
while ((rand()% 49)>0; (rand()% 49)!=a)
Edit2->Text=(rand()% 49);