Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
GenerativeComponents
  • Product Communities
  • More
GenerativeComponents
GenerativeComponents Community Wiki Create a Set of Random Points
    • Sign in
    • +An Overview of GenerativeComponents
    • +Addin Content
    • +Bentley BIM Modeler Accreditation – Program Overview
    • +C# Sample Solution and other Add-ins
    • +GenerativeComponents Solutions
    • +Learn GenerativeComponents
    • +Reference Material
    • Support for GenerativeComponents
    • -Tutorials
      • 3D array copy surface
      • Add RFA data as BuildingContent to ABD with GC Extension
      • Cell Feature
      • Create a Set of Random Points
      • Creation of Global function from Custom function
      • Creation of Parabolic curve
      • Free Form Roof Example
      • GC Excel Feature
      • GenerativeComponents Essentials Course
      • How To Create Surface From Lines & Curves
      • How to Export GC elements
      • How to get concrete sections in the cross-section dialog in Generative Components
      • Landscape Bridge Example
      • +LawCurve
      • List Of Points With A Loop Example
      • Mesh feature 3d print
      • Modular Multiplication On Circle
      • +Operation Node
      • +Optimization with the Optimizer node type
      • Palm Tree Modeler
      • Point By Function Example
      • Points On Curve
      • Prime Number Pattern
      • Selection of Points
      • Selection of points based on Query Expressions
      • Selection of points based on range of indices
      • Set a New Property Value to a Set of Selected Nodes
      • Simple Bridge Example
      • Simple Equations To Describe Form Example
      • Simple Free Form Roof Example
      • Sin Tower
      • Skeleton
      • Sunflower Seed Pattern Modelling
      • Surface Division Basic Steps
      • Surface from Rails and Swept Sections
      • The use of Packager in Generative Components
      • +Tools and Techniques
      • Ulam Spiral From A Rectangular Spiral
      • Video Tutorials
      • Video Tutorials - Short Techniques
    • +User Projects
    • +Visualized Parametric Experimentations
    • +zed_Older Content

     
     Questions about this article, topic, or product? Click here. 

    Create a Set of Random Points

      Product(s): OpenBuildings Generative Components
      Version(s): CONNECT Edition
      Environment:  N\A

     

    Problem

    How to create a set of random points confined within a range?

    Solution

    We can create a set of random points using the Random() function. It returns a random number in the specified range.

    object Random(optional int n1, optional int n2)
    If called with no arguments, returns a random double in the range 0.0 ≤ r < 1.0.
    If called with one argument (n1), returns a random integer in the range 0 ≤ r < n1.
    If called with two arguments (n1 and n2), returns a random integer in the range n1 ≤ r < n2. 

    The set of random points can be confined within a range formed by coordinates (Xmin,Ymin) and (Xmax,Ymax).
    To create the points "byfunction" technique is used and below is the code.

    function(int n, int Ymin, int Ymax, int Xmin, int Xmax, CoordinateSystem CS)
    {
     
        for(int i=0; i<n; i++) 
        {
           Point PointX = new Point(this); 
           PointX.ByCartesianCoordinates(CS, Random(Xmin,Xmax), Random(Ymin,Ymax),0);
        }
     
    }

    Click here to play this video

    The SetRandomSeed() function can also be used along Random() function. This is useful if we want the same sequence of random numbers every time.

    function(int n, int Ymin, int Ymax, int Xmin, int Xmax, CoordinateSystem CS)
    {
        SetRandomSeed(100);
        for(int i=0; i<n; i++) 
        {
           Point PointX = new Point(this); 
           PointX.ByCartesianCoordinates(CS, Random(Xmin,Xmax), Random(Ymin,Ymax),0);
        }
     
    }


    Click here to play this video

    Please go through the sample file Random Points.gct

    • Point
    • GenerativeComponents
    • random
    • GCscript
    • GenerativeComponents CONNECT Edition
    • OpenBuildings GenerativeComponents
    • GC
    • Share
    • History
    • More
    • Cancel
    • Anik Mal Created by Bentley Colleague Anik Mal
    • When: Tue, Mar 31 2020 1:53 AM
    • Anik Mal Last revision by Bentley Colleague Anik Mal
    • When: Fri, May 15 2020 12:25 PM
    • Revisions: 13
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies