File: compatibility.cpp

package info (click to toggle)
freespace2 3.7.4%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: buster
  • size: 22,236 kB
  • sloc: cpp: 393,535; ansic: 4,106; makefile: 1,091; xml: 181; sh: 137
file content (29 lines) | stat: -rw-r--r-- 648 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "globalincs/compatibility.h"
#include "stdlib.h"

int rand_function(int limit)
{
	return (rand() % limit);
}

// adapted from http://www.cplusplus.com/reference/algorithm/random_shuffle/
void random_shuffle(int *first, int *last)
{
	random_shuffle(first, last, rand_function);
}

// adapted from http://www.cplusplus.com/reference/algorithm/random_shuffle/
template <class RandomNumberGenerator>
void random_shuffle(int *first, int *last, RandomNumberGenerator& custom_rand)
{
	int i, n, temp;
	n = (last-first);

	for (i=n-1; i>0; --i)
	{
		int pos = custom_rand(i+1);
		temp = first[i];
		first[i] = first[pos];
		first[pos] = temp;
	}
}