\n","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"We are excited to share that we have once again expanded the functionality of our Relational Knowledge Graph Management System (RKGMS). We have implemented multiple "},{"type":"a","url":"https://en.wikipedia.org/wiki/Pseudorandom_number_generator","title":null,"children":[{"type":"text","text":"pseudorandom number generators"}]},{"type":"text","text":" (PRNGs) that can now be used to build probabilistic models in Rel. Specifically, three general-purpose PRNGs are currently available via our "},{"type":"a","url":"https://docs.relational.ai/rel/ref/lib/stdlib","title":null,"children":[{"type":"text","text":"Rel Standard Library"}]},{"type":"text","text":":"}]},{"type":"ul","children":[{"type":"li","children":[{"type":"lic","children":[{"type":"a","url":"#mersenne-twister","title":null,"children":[{"type":"text","text":"Mersenne Twister"}]}]}]},{"type":"li","children":[{"type":"lic","children":[{"type":"a","url":"#threefry","title":null,"children":[{"type":"text","text":"Threefry"}]}]}]},{"type":"li","children":[{"type":"lic","children":[{"type":"a","url":"#random-device","title":null,"children":[{"type":"text","text":"Random Device"}]}]}]}]},{"type":"h2","children":[{"type":"text","text":"Mersenne Twister"}],"id":"mersenne-twister"},{"type":"p","children":[{"type":"a","url":"https://en.wikipedia.org/wiki/Mersenne_Twister","title":null,"children":[{"type":"text","text":"Mersenne Twister"}]},{"type":"text","text":" is one of the most widely used PRNGs. In Rel, the relation "},{"type":"text","text":"random_mersenne_twister","code":true},{"type":"text","text":" generates a floating-point random number (between "},{"type":"text","text":"0.0","code":true},{"type":"text","text":" and "},{"type":"text","text":"1.0","code":true},{"type":"text","text":") for every tuple in a relation:"}]},{"type":"code_block","lang":"rel","value":"random_mersenne_twister[42, {(1, \"January\"); (2, \"February\")}]","children":[{"type":"text","text":""}]},{"type":"code_block","lang":"rel","value":"def output = random_mersenne_twister[42, {(1, \"January\"); (2, \"February\")}]","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Providing the seed (here: "},{"type":"text","text":"42","code":true},{"type":"text","text":") ensures that the Rel model is deterministic and reproducible—meaning it always re-evaluates to the same pseudorandom number."}]},{"type":"p","children":[{"type":"text","text":"As well as numbers, "},{"type":"text","text":"DateTime","code":true},{"type":"text","text":" data can also be used as seeds."}]},{"type":"code_block","lang":"rel","value":"random_mersenne_twister[datetime_now, range[1, 5, 1]]","children":[{"type":"text","text":""}]},{"type":"code_block","lang":"rel","value":"random_mersenne_twister[datetime_now, range[1, 5, 1]]","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"The relation "},{"type":"text","text":"range","code":true},{"type":"text","text":" can be used to conveniently create five random numbers."}]},{"type":"h2","children":[{"type":"text","text":"Threefry"}],"id":"threefry"},{"type":"p","children":[{"type":"a","url":"https://en.wikipedia.org/wiki/Counter-based_random_number_generator_(CBRNG)","title":null,"children":[{"type":"text","text":"Threefry"}]},{"type":"text","text":" is a simplified "},{"type":"a","url":"https://en.wikipedia.org/wiki/Threefish","title":null,"children":[{"type":"text","text":"Threefish"}]},{"type":"text","text":" algorithm which uses a UInt64 state space."}]},{"type":"p","children":[{"type":"text","text":"The relations "},{"type":"text","text":"random_threefry_uint64","code":true},{"type":"text","text":" and "},{"type":"text","text":"random_threefry_float64","code":true},{"type":"text","text":" can be used to create random "},{"type":"text","text":"UInt64","code":true},{"type":"text","text":" and "},{"type":"text","text":"Float64","code":true},{"type":"text","text":" numbers."}]},{"type":"code_block","lang":"rel","value":"def output:uint64 = random_threefry_uint64[1234, 3]\ndef output:float64 = random_threefry_float64[1234, 3]","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"The random floating-point numbers lie between "},{"type":"text","text":"0.0","code":true},{"type":"text","text":" and "},{"type":"text","text":"1.0","code":true},{"type":"text","text":", whereas the random "},{"type":"text","text":"UInt64","code":true},{"type":"text","text":" numbers are distributed over the entire "},{"type":"text","text":"UInt64","code":true},{"type":"text","text":" value range."}]},{"type":"p","children":[{"type":"text","text":"In contrast to the "},{"type":"a","url":"#mersenne-twister","title":null,"children":[{"type":"text","text":"Mersenne Twister"}]},{"type":"text","text":" implementation, the Threefry implementation is first-order, meaning it expects individual "},{"type":"text","text":"Int64","code":true},{"type":"text","text":" or "},{"type":"text","text":"UInt64","code":true},{"type":"text","text":" values rather than relations with arity greater than "},{"type":"text","text":"1","code":true},{"type":"text","text":"."}]},{"type":"p","children":[{"type":"text","text":"It is even possible to create independent random sequences, where the seed itself is randomly generated."}]},{"type":"code_block","lang":"rel","value":"def seed = random_threefry_uint64[1234, 0]\ndef output = random_threefry_float64[seed, i]\n for i in range[1, 3, 1]","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Threefry falls in the class of "},{"type":"a","url":"https://en.wikipedia.org/wiki/Counter-based_random_number_generator_(CBRNG)","title":null,"children":[{"type":"text","text":"counter-based random number generators"}]},{"type":"text","text":" which are well-suited for generating random numbers in a highly parallelized fashion using multiple CPU threads or GPUs."}]},{"type":"h2","children":[{"type":"text","text":"Random Device"}],"id":"random-device"},{"type":"p","children":[{"type":"text","text":"The relations "},{"type":"text","text":"random_unit64","code":true},{"type":"text","text":" and "},{"type":"text","text":"random_uint128","code":true},{"type":"text","text":" use a hardware-based random device provided by the system to generate random numbers."}]},{"type":"code_block","lang":"rel","value":"def output:uint64 = random_uint64\ndef output:uint128 = random_uint128","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"No seed is needed because the randomness is hardware-based."}]},{"type":"p","children":[{"type":"text","text":"Due to the nature of the random device, the generated random numbers are not reproducible and change for every transaction. This can have huge performance impact and negative consequences for incremental view maintenance as values change every time this relation is re-evaluated."}]},{"type":"p","children":[{"type":"text","text":"In contrast to the "},{"type":"a","url":"#mersenne-twister","title":null,"children":[{"type":"text","text":"Mersenne Twister"}]},{"type":"text","text":" and "},{"type":"a","url":"#threefry","title":null,"children":[{"type":"text","text":"Threefry"}]},{"type":"text","text":" PRNGs, the relations "},{"type":"text","text":"random_unit64","code":true},{"type":"text","text":" and "},{"type":"text","text":"random_uint128","code":true},{"type":"text","text":" produce only single random numbers and cannot produce sequences of random numbers in Rel."}]},{"type":"p","children":[{"type":"text","text":"The random number from "},{"type":"text","text":"random_unit64","code":true},{"type":"text","text":" can also be used as a seed for Mersenne Twister and Threefry, chaining different PRNGs together."}]},{"type":"code_block","lang":"rel","value":"def data = {1; 2}\n\ndef my_numbers:MT =\n random_mersenne_twister[random_uint64, data]\n\ndef my_numbers:threefry =\n random_threefry_float64[random_uint64, i]\n for i in data\n\ndef output = table[my_numbers]","children":[{"type":"text","text":""}]},{"type":"html","value":"","children":[{"type":"text","text":""}]},{"type":"h2","children":[{"type":"text","text":"What's Next?"}],"id":"what-s-next"},{"type":"p","children":[{"type":"text","text":"If you have a favorite PRNG that you would like to see in Rel, please "},{"type":"a","url":"/contact-us","title":null,"children":[{"type":"text","text":"let us know"}]},{"type":"text","text":"."}]},{"type":"p","children":[{"type":"text","text":"Stay tuned as we are developing a uniform interface which can be used across all our pseudorandom number generators."}]}],"_content_source":{"queryId":"src/content/resources/random-number-generators-in-rel.mdx","path":["resource","body"]}},"_content_source":{"queryId":"src/content/resources/random-number-generators-in-rel.mdx","path":["resource"]}}},"errors":null,"query":"\n query resource($relativePath: String!) {\n resource(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...ResourceParts\n }\n}\n \n fragment ResourceParts on Resource {\n __typename\n title\n description\n date\n image\n categories\n authors {\n __typename\n name\n link\n }\n seo {\n __typename\n keywords\n description\n image\n image_alt\n canonical_url\n author\n published\n modified\n language\n robots\n site_name\n content_type\n }\n body\n}\n ","variables":{"relativePath":"random-number-generators-in-rel.mdx"}},"src/content/meta/meta.md":{"data":{"meta":{"_sys":{"filename":"meta","basename":"meta.md","breadcrumbs":["meta"],"path":"src/content/meta/meta.md","relativePath":"meta.md","extension":".md"},"id":"src/content/meta/meta.md","__typename":"Meta","banner":{"__typename":"MetaBanner","enabled":true,"content":{"type":"root","children":[{"type":"p","children":[{"type":"text","text":"Check out "},{"type":"a","url":"/resources/highlights-of-relationalai-at-snowflake-data-cloud-summit-2024","title":"SF summit highlights","children":[{"type":"text","text":"highlights"}]},{"type":"text","text":" of RelationalAI at "},{"type":"text","text":"Snowflake's Data Cloud Summit 2024!","bold":true}]}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner","content"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner"]}},"header":{"__typename":"MetaHeader","links":[{"__typename":"MetaHeaderLinks","text":"Product","url":"/product","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",0]}},{"__typename":"MetaHeaderLinks","text":"Company","url":"/company","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",1]}},{"__typename":"MetaHeaderLinks","text":"Docs","url":"/docs/getting_started","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",2]}},{"__typename":"MetaHeaderLinks","text":"Resources","url":"/resources/all/1","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",3]}},{"__typename":"MetaHeaderLinks","text":"get-started","url":"/get-started","style":"cta","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",4]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header"]}},"footer":{"__typename":"MetaFooter","sections":[{"__typename":"MetaFooterSections","name":"Product","links":[{"__typename":"MetaFooterSectionsLinks","text":"Overview","url":"/product","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Use Cases","url":"/product#for-problems-that-matter","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Capabilities","url":"/product#a-new-toolset","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0]}},{"__typename":"MetaFooterSections","name":"Resources","links":[{"__typename":"MetaFooterSectionsLinks","text":"Documentation","url":"/docs/getting_started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Blog","url":"/resources/all/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"News","url":"/resources/news/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Research","url":"/resources/research/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",3]}},{"__typename":"MetaFooterSectionsLinks","text":"Releases","url":"/resources/releases/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",4]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1]}},{"__typename":"MetaFooterSections","name":"About Us","links":[{"__typename":"MetaFooterSectionsLinks","text":"Our Company","url":"/company","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Contact Us","url":"/get-started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Careers","url":"/careers","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Legal","url":"/legal","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",3]}},{"__typename":"MetaFooterSectionsLinks","text":"Security & Trust","url":"https://trust.relational.ai/","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",4]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2]}}],"socials":[{"__typename":"MetaFooterSocials","text":"GitHub","url":"https://github.com/RelationalAI","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/github.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",0]}},{"__typename":"MetaFooterSocials","text":"LinkedIn","url":"https://www.linkedin.com/company/relationalai/about","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/linkedin.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",1]}},{"__typename":"MetaFooterSocials","text":"Twitter","url":"https://twitter.com/relationalai","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/twitter.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta"]}}},"errors":null,"query":"\n query meta($relativePath: String!) {\n meta(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...MetaParts\n }\n}\n \n fragment MetaParts on Meta {\n __typename\n banner {\n __typename\n enabled\n content\n }\n header {\n __typename\n links {\n __typename\n text\n url\n style\n }\n }\n footer {\n __typename\n sections {\n __typename\n name\n links {\n __typename\n text\n url\n }\n }\n socials {\n __typename\n text\n url\n icon\n }\n }\n}\n ","variables":{"relativePath":"./meta.md"}}};
globalThis.tina_info = tina;
})();
Random Number Generators in Rel · RelationalAI
Check out highlights of RelationalAI at Snowflake's Data Cloud Summit 2024!
We are excited to share that we have once again expanded the functionality of our Relational Knowledge Graph Management System (RKGMS). We have implemented multiple pseudorandom number generators (PRNGs) that can now be used to build probabilistic models in Rel. Specifically, three general-purpose PRNGs are currently available via our Rel Standard Library:
Mersenne Twister is one of the most widely used PRNGs. In Rel, the relation random_mersenne_twister generates a floating-point random number (between 0.0 and 1.0) for every tuple in a relation:
Providing the seed (here: 42) ensures that the Rel model is deterministic and reproducible—meaning it always re-evaluates to the same pseudorandom number.
As well as numbers, DateTime data can also be used as seeds.
The random floating-point numbers lie between 0.0 and 1.0, whereas the random UInt64 numbers are distributed over the entire UInt64 value range.
In contrast to the Mersenne Twister implementation, the Threefry implementation is first-order, meaning it expects individual Int64 or UInt64 values rather than relations with arity greater than 1.
It is even possible to create independent random sequences, where the seed itself is randomly generated.
def seed = random_threefry_uint64[1234, 0]
def output = random_threefry_float64[seed, i]
for i in range[1, 3, 1]
Threefry falls in the class of counter-based random number generators which are well-suited for generating random numbers in a highly parallelized fashion using multiple CPU threads or GPUs.
Random Device
The relations random_unit64 and random_uint128 use a hardware-based random device provided by the system to generate random numbers.
No seed is needed because the randomness is hardware-based.
Due to the nature of the random device, the generated random numbers are not reproducible and change for every transaction. This can have huge performance impact and negative consequences for incremental view maintenance as values change every time this relation is re-evaluated.
In contrast to the Mersenne Twister and Threefry PRNGs, the relations random_unit64 and random_uint128 produce only single random numbers and cannot produce sequences of random numbers in Rel.
The random number from random_unit64 can also be used as a seed for Mersenne Twister and Threefry, chaining different PRNGs together.
def data = {1; 2}
def my_numbers:MT =
random_mersenne_twister[random_uint64, data]
def my_numbers:threefry =
random_threefry_float64[random_uint64, i]
for i in data
def output = table[my_numbers]
What's Next?
If you have a favorite PRNG that you would like to see in Rel, please let us know.
Stay tuned as we are developing a uniform interface which can be used across all our pseudorandom number generators.