本文整理汇总了C++中SkRandom::nextS方法的典型用法代码示例。如果您正苦于以下问题:C++ SkRandom::nextS方法的具体用法?C++ SkRandom::nextS怎么用?C++ SkRandom::nextS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkRandom
的用法示例。
在下文中一共展示了SkRandom::nextS方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: random_rect
static SkIRect random_rect(SkRandom& rand) {
SkIRect rect = {0,0,0,0};
while (rect.isEmpty()) {
rect.fLeft = rand.nextS() % MAX_SIZE;
rect.fRight = rand.nextS() % MAX_SIZE;
rect.fTop = rand.nextS() % MAX_SIZE;
rect.fBottom = rand.nextS() % MAX_SIZE;
rect.sort();
}
return rect;
}
示例2: rand_rect
static SkIRect rand_rect(SkRandom& rand, int n) {
int x = rand.nextS() % n;
int y = rand.nextS() % n;
int w = rand.nextU() % n;
int h = rand.nextU() % n;
return SkIRect::MakeXYWH(x, y, w, h);
}
示例3: onOnceBeforeDraw
void onOnceBeforeDraw() override {
SkRandom rand;
int steps = 20;
SkScalar dist = SkIntToScalar(400);
SkScalar x = SkIntToScalar(20);
SkScalar y = SkIntToScalar(50);
fPath.moveTo(x, y);
for (int i = 0; i < steps; i++) {
x += dist/steps;
SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25);
if (i == steps/2) {
fPath.moveTo(x, tmpY);
} else {
fPath.lineTo(x, tmpY);
}
}
{
SkRect oval;
oval.set(SkIntToScalar(20), SkIntToScalar(30),
SkIntToScalar(100), SkIntToScalar(60));
oval.offset(x, 0);
fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8));
}
fClickPt.set(SkIntToScalar(200), SkIntToScalar(200));
this->setBGColor(0xFFDDDDDD);
}
示例4: test_search
static void test_search(skiatest::Reporter* reporter) {
int i, array[kSEARCH_COUNT];
SkRandom rand;
for (i = 0; i < kSEARCH_COUNT; i++) {
array[i] = rand.nextS();
}
SkTHeapSort<int>(array, kSEARCH_COUNT);
// make sure we got sorted properly
for (i = 1; i < kSEARCH_COUNT; i++) {
REPORTER_ASSERT(reporter, array[i-1] <= array[i]);
}
// make sure we can find all of our values
for (i = 0; i < kSEARCH_COUNT; i++) {
int index = SkTSearch<int>(array, kSEARCH_COUNT, array[i], sizeof(int));
REPORTER_ASSERT(reporter, index == i);
}
// make sure that random values are either found, or the correct
// insertion index is returned
for (i = 0; i < 10000; i++) {
int value = rand.nextS();
int index = SkTSearch<int>(array, kSEARCH_COUNT, value, sizeof(int));
if (index >= 0) {
REPORTER_ASSERT(reporter,
index < kSEARCH_COUNT && array[index] == value);
} else {
index = ~index;
REPORTER_ASSERT(reporter, index <= kSEARCH_COUNT);
if (index < kSEARCH_COUNT) {
REPORTER_ASSERT(reporter, value < array[index]);
if (index > 0) {
REPORTER_ASSERT(reporter, value > array[index - 1]);
}
} else {
// we should append the new value
REPORTER_ASSERT(reporter, value > array[kSEARCH_COUNT - 1]);
}
}
}
}
示例5: ff
DEF_TEST(ClampRange, reporter) {
gReporter = reporter;
test_range(0, 0, 20);
test_range(0xFFFF, 0, 20);
test_range(-ff(2), 0, 20);
test_range( ff(2), 0, 20);
test_range(-10, 1, 20);
test_range(10, -1, 20);
test_range(-10, 3, 20);
test_range(10, -3, 20);
test_range(ff(1), ff(16384), 100);
test_range(ff(-1), ff(-16384), 100);
test_range(ff(1)/2, ff(16384), 100);
test_range(ff(1)/2, ff(-16384), 100);
SkRandom rand;
// test non-overflow cases
for (int i = 0; i < 1000000; i++) {
SkFixed fx = rand.nextS() >> 1;
SkFixed sx = rand.nextS() >> 1;
int count = rand.nextU() % 1000 + 1;
SkFixed dx = (sx - fx) / count;
test_range(fx, dx, count);
}
// test overflow cases
for (int i = 0; i < 100000; i++) {
SkFixed fx = rand.nextS();
SkFixed dx = rand.nextS();
int count = rand.nextU() % 1000 + 1;
test_range(fx, dx, count);
}
}
示例6: SkQSort_UnitTest
void SkQSort_UnitTest()
{
#ifdef SK_SUPPORT_UNITTEST
int array[100];
SkRandom rand;
for (int i = 0; i < 1000; i++)
{
int j, count = rand.nextRangeU(1, SK_ARRAY_COUNT(array));
for (j = 0; j < count; j++)
array[j] = rand.nextS() & 0xFF;
SkQSort(array, count, sizeof(int), compare_int);
for (j = 1; j < count; j++)
SkASSERT(array[j-1] <= array[j]);
}
#endif
}
示例7: rand_proc
static void rand_proc(int array[N]) {
SkRandom rand;
for (int i = 0; i < N; ++i) {
array[i] = rand.nextS();
}
}