vendredi 16 novembre 2018

randomized array of numbers in wont pass integer range?

long long x[1000000], n, small, big;
    main(){
        cin >> n; //range
        cin >> small; cin >> big;
        srand(time(NULL));
        for (int i=0; i<n; i++){
            x[i]=small + rand()%(big-small+1);
        }
        merge_sort(x,0,n-1);
        for (int i=0; i<n; i++){
            cout << x[i] << " ";
        }
    }

(ignore the merge_sort, i only used it to see the highest number)

So i make sure all the variables is in long long, yet all the randomized x[i] wont pass integer range (32768). Anyone have any idea why?

some example




Aucun commentaire:

Enregistrer un commentaire