Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Javascript

Name: Anonymous 2012-10-04 22:59

How do I create 3 random numbers and make it so those numbers are not the same?

Name: Anonymous 2012-10-04 23:04

var random_numbers = [ Math.random(), 1 + Math.random(), 2 + Math.random() ];

Name: Anonymous 2012-10-04 23:10

>>2
You're retarded. If the first Math.random() returned 10, the second returned 9, and the third returned 8, you'd be fucked.

// Generate 3 different random numbers (v2.0)
var r = Math.random();
var random_numbers = [r, r + 1, r + 2];

Name: Anonymous 2012-10-04 23:14

var random_numbers = [6, 3, 7];

Name: Anonymous 2012-10-04 23:22

>>3
You obviously don't know what Math.random() does. It can't return 10, 9, or 8.

Name: mjgjmgptwjmgptwjmgptw 2012-10-04 23:28

Or you could just write a conditional that rolls again if thd numbers match
DUH DUH DUH MAJ DUH TO DUH.

Name: Anonymous 2012-10-04 23:36

>>3
Aaaaaaahhh haa haa haa haaaaaaaah retarded, huh?

Name: Anonymous 2012-10-05 0:43

http://en.wikipedia.org/wiki/Fisher-Yates_shuffle


void random_numbers(int n, int m, int *num)
{
    int i, in, im, *is_used;
    srand((unsigned int) time(NULL));
    is_used = malloc(n * sizeof(int));

    for (i = 0; i < n; ++i) {
        is_used[i] = 0;
    }

    im = 0;

    for (in = n - m; in < n && im < m; ++in) {
        int r = rand() % (in + 1);
        if (is_used[r])
            r = in;
        assert(!is_used[r]);
        num[im++] = r;
        is_used[r] = 1;
    }

    assert(im = m);
    free(is_used);
}

Name: Anonymous 2012-10-05 6:42

>>5
Sure, he's retarded, but is he Leah retarded?

Name: Anonymous 2012-10-05 7:22

ITT: expert Debian programmers

Name: Anonymous 2012-10-05 7:59

>>9
DOn't insult Princess Leah, you bitter virgin!

Name: Anonymous 2012-10-05 10:07

>>11
Princess Leah ain't got shit on The Queen.

Queen Reimu wants you to /polecat kebabs/.

Don't change these.
Name: Email:
Entire Thread Thread List