int64_t random_64(void)
{
    int64_t r = random_32();
    r <<= 32;
    r |= random_32();
    return r;
}
示例#2
0
uint64 random_64()
{
    uint64 a = random_32();
    uint64 b = random_32();

    return (a << 32) + b;
}
/*
 * Pick a move out of the current book. If |pos| is not in the book, return
 * NO_MOVE. If more than one alternative exists, choose randomly among all
 * weighted possibilities.
 */
move_t get_poly_book_move(position_t* pos)
{
    uint64_t key = book_hash(pos);
    int offset = find_book_key(key);
    if (offset == -1) return NO_MOVE;

    move_t moves[255];
    uint16_t weights[255];
    uint16_t total_weight = 0;
    int index = 0;
    book_entry_t entry;
    // Read all book entries with the correct key. They're all stored
    // contiguously, so just scan through as long as the key matches.
    while (true) {
        assert(offset+index < num_entries);
        read_book_entry(offset+index, &entry);
        if (entry.key != key) break;
        moves[index] = book_move_to_move(pos, entry.move);
        printf("info string book move ");
        print_coord_move(moves[index]);
        printf("weight %d\n", entry.weight);
        weights[index++] = total_weight + entry.weight;
        total_weight += entry.weight;
    }
    if (index == 0) return NO_MOVE;

    // Choose randomly amonst the weighted options.
    uint16_t choice = random_32() % total_weight;
    int i;
    for (i=0; choice >= weights[i]; ++i) {}
    assert(i < index);
    return moves[i];
}
示例#4
0
uint32 random_between(uint32 min, uint32 max)
{
    if(min == max)
    {
        return min;
    }

    if(min > max)
    {
        swap(min, max);
    }
    
    const uint32 diff = max - min + 1;

    return min + random_32() % diff;
}