Lev Walkin | a5972be | 2017-09-29 23:15:58 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 11 | int |
| 12 | asn_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 | |
| 24 | intmax_t |
| 25 | asn_random_between(intmax_t a, intmax_t b) { |
| 26 | assert(a <= b); |
| 27 | assert((b-a) < RAND_MAX); |
| 28 | if(a == b) return a; |
| 29 | return a + (random() % (b - a)); |
| 30 | } |