blob: 8878527722da4c391d0ab6807713765d070fa3c8 [file] [log] [blame]
Lev Walkina5972be2017-09-29 23:15:58 -07001/*
2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
4 * Redistribution and modifications are permitted subject to BSD license.
5 */
Lev Walkina5972be2017-09-29 23:15:58 -07006#include <asn_internal.h>
7#include <asn_random_fill.h>
8#include <constr_TYPE.h>
9
10int
11asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
12 size_t length) {
13
14 if(td && td->op->random_fill) {
15 asn_random_fill_result_t res =
16 td->op->random_fill(td, struct_ptr, 0, length);
17 return (res.code == ARFILL_OK) ? 0 : -1;
18 } else {
19 return -1;
20 }
21}
22
23intmax_t
24asn_random_between(intmax_t a, intmax_t b) {
25 assert(a <= b);
26 assert((b-a) < RAND_MAX);
27 if(a == b) return a;
Lev Walkin4d8b7482017-10-01 14:14:20 -070028 return a + (random() % (b - a + 1));
Lev Walkina5972be2017-09-29 23:15:58 -070029}