blob: a9877cf30e9e5aeae04797b030fb3f197cff7f1d [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 */
6
7#include <asn_internal.h>
8#include <asn_random_fill.h>
9#include <constr_TYPE.h>
10
11int
12asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr,
13 size_t length) {
14
15 if(td && td->op->random_fill) {
16 asn_random_fill_result_t res =
17 td->op->random_fill(td, struct_ptr, 0, length);
18 return (res.code == ARFILL_OK) ? 0 : -1;
19 } else {
20 return -1;
21 }
22}
23
24intmax_t
25asn_random_between(intmax_t a, intmax_t b) {
26 assert(a <= b);
27 assert((b-a) < RAND_MAX);
28 if(a == b) return a;
Lev Walkin4d8b7482017-10-01 14:14:20 -070029 return a + (random() % (b - a + 1));
Lev Walkina5972be2017-09-29 23:15:58 -070030}