srand((unsigned)time(NULL)); int a[] = {0,1,0,1,2,3,4,5,6,78,9}; int b = rand() % (x2-x2)+x1; cout<<a[b]<<endl;