# Automatically creating cstruct instances

**URL:** <https://racket.discourse.group/t/automatically-creating-cstruct-instances/2470>\
**Category:** Questions & Answers\
**Created:** [November 6, 2023, 9:22am UTC](https://racket.discourse.group/t/automatically-creating-cstruct-instances/2470 "2023-11-06T09:22:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![db7](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/db7/32/1470_2.png) [@db7](https://racket.discourse.group/u/db7)\
**Post date:** [November 6, 2023, 9:22am UTC](https://racket.discourse.group/t/automatically-creating-cstruct-instances/2470/1 "2023-11-06T09:22:40Z")

</div>

Hi there,

is there any tool to automatically create instances of cstructs? I was trying to use `contract-random-generate` for that, but it doesn't seem to support it out of the box.

In more detail, I have create several (hundreds) of cstructs with ffi/unsafe. Now I'd like to create random _valid_ values to each of those instructions. Purely random values are easy to create. I just allocate the cstruct instance and initialize it with garbage. But I would like to use the cstruct types to create a value. `ctype->layout` gives me some useful information, but converts enums to integers, so I lose too much information. Is there a tool/lib/pattern that can help me here?
