{"id":32224,"date":"2022-07-25T12:57:15","date_gmt":"2022-07-25T07:27:15","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=32224"},"modified":"2022-07-25T12:57:15","modified_gmt":"2022-07-25T07:27:15","slug":"how-to-generate-a-random-number-using-rand-and-randbetween-function-in-canvas-app","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/07\/how-to-generate-a-random-number-using-rand-and-randbetween-function-in-canvas-app\/","title":{"rendered":"How to generate a random number using Rand() and RandBetween() function in Canvas App"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>In this blog, we will learn how we can create one random color in RGBA format by generating random numbers.<\/p>\n<p><strong>Problem:<\/strong><\/p>\n<p>We have a Canvas App, where we have created one Display Form. Here, we have displayed the list of categories of All Accounts in the color-coded format as shown in the below screenshot. In the below screen we want categories of all Accounts to be shown in color-coded format, so it is necessary to display all categories of Accounts in Unique colors. For this, we want to generate random colors for each industry and assign them to a specific category.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-32225\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App.jpeg\" alt=\"Canvas App\" width=\"1365\" height=\"651\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App.jpeg 1365w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App-300x143.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App-1024x488.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App-768x366.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/Canvas-App-660x315.jpeg 660w\" sizes=\"(max-width: 1365px) 100vw, 1365px\" \/><\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>We can generate the random color using <strong>Rand() or RandBetween()<\/strong> function in Canvas App. Please find the below syntax for the above function.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p><strong>Rand() = <\/strong>This function will generate one random number greater than 0 but less than 1. <strong>For example 0.26786, 0.65784.<\/strong><\/p>\n<p><strong>RandBetween(START_RANGE, END_RANGE) = <\/strong>This function will return the whole number between the range that we provide to the function.<\/p>\n<p>Where,<\/p>\n<ol>\n<li><strong>START_RANGE<\/strong> \u2013 It is a numeric value that states the starting range of the random number which we want to generate.<\/li>\n<li><strong>END_RANGE<\/strong> &#8211; It is a numeric value that state the ending range of the random number which we want to generate.<\/li>\n<\/ol>\n<blockquote><p><strong><em>Note: After applying the above Power Fx function, one whole number will be generated between the range that we provide to the RandBetween() function.<\/em><\/strong><\/p><\/blockquote>\n<p>Please find the below Power Fx formulas that we have used to generate the random color for each category checkbox.<\/p>\n<p><strong><em>UpdateContext({red:RandBetween( 0, 99 )});<\/em><\/strong><\/p>\n<p><strong><em>UpdateContext({green:RandBetween( 0, 99 )});<\/em><\/strong><\/p>\n<p><strong><em>UpdateContext({blue:RandBetween( 0, 99 )});<\/em><\/strong><\/p>\n<p>In the above code we have generated the three random numbers for each industry and assigned a color to that category legend by using generated numbers in RGBA format as shown in the above screenshot:<\/p>\n<p><strong><em>RGBA(red,green,blue,1) <\/em><\/strong><\/p>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>In this way, by using Rand() or RandBetween() function we can create or generate a random number to process any operation in Canvas App.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/mailchimp-dynamics-365-crm-integration-marketing-4-dynamics\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone  wp-image-32226\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/m4d.jpg\" alt=\"\" width=\"840\" height=\"210\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/m4d.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/m4d-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/m4d-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/07\/m4d-660x165.jpg 660w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we will learn how we can create one random color in RGBA format by generating random numbers. Problem: We have a Canvas App, where we have created one Display Form. Here, we have displayed the list of categories of All Accounts in the color-coded format as shown in the below screenshot.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/07\/how-to-generate-a-random-number-using-rand-and-randbetween-function-in-canvas-app\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1954,18,2361],"tags":[1867],"class_list":["post-32224","post","type-post","status-publish","format-standard","hentry","category-canvas-apps","category-dynamics-365-v9-2","category-technical","tag-canvas-app"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=32224"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/32224\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=32224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=32224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=32224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}