1. Home
    1. Dashboard
    2. Search
  2. Forum
    1. Unresolved Threads
    2. Members
      1. Recent Activities
      2. Users Online
      3. Team Members
      4. Search Members
      5. Trophys
  3. Articles
  4. Blog
  5. Videos
  6. Jobs
  7. Shop
    1. Orders
  • Login or register
  • Search
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Blog Articles
  • Products
  • More Options
  1. Robotforum - Support and discussion community for industrial robots and cobots
  2. Forum
  3. Industrial Robot Support and Discussion Center
  4. KUKA Robot Forum
Your browser does not support videos RoboDK Software for simulation and programming
Visit our Mainsponsor
IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Sponsored Ads

Generating Random Numbers?

  • AiSard
  • June 11, 2018 at 10:57 AM
  • Thread is Resolved
  • AiSard
    Reactions Received
    1
    Trophies
    3
    Posts
    44
    • June 11, 2018 at 10:57 AM
    • #1

    Is there a way to generate a random number in KRL?
    I've been using a work-around via RSI,
    But no RSI in this project so was trying to figure out a way to hack one in

    KR C4 compact
    KSS 8.3.25

  • Fubini
    Reactions Received
    278
    Trophies
    9
    Posts
    1,889
    • June 12, 2018 at 6:31 AM
    • #2

    Yes you can. You can use CWrite with $FCT_CALL as Parameter. It lets you call built-in functions like krl_getRandomSeed() and krl_getRandom(). Internally these call the c-style rand() function.

    Please find in the attachment my implementation of KRL Interface functions that I usually use for this kind of purpose.

    Fubini

    Files

    KRLRandom.zip 3.04 kB – 182 Downloads
  • AiSard
    Reactions Received
    1
    Trophies
    3
    Posts
    44
    • June 18, 2018 at 8:53 AM
    • #3

    Hm, not sure what I'm doing wrong, but the CWRITE function keeps spitting out a "Random Value Invalid" error.. Doesn't seem to matter if its inline, subprogram or function..

    Code
    DECL E6POS rPos
    ...
    rPos.X = RandomInt(0,300)
    ...
    DEFFCT INT RandomInt(Min:in, Max:in)
    	DECL INT Min
    	DECL INT Max
    	DECL INT Random
    	DECL STATE_T State
    	DECL MODUS_T Mode
    
    
    	CWrite ($Fct_Call, State, Mode, "krl_getRandom", Random, Min, Max)
    	Return Random
    ENDFCT
    Display More

    Am I doing something wrong? I'm not so versed in Interface functions(?) or anything that uses more than the single .src file so might be fudging something up..

  • AiSard
    Reactions Received
    1
    Trophies
    3
    Posts
    44
    • June 18, 2018 at 9:06 AM
    • #4

    Aaand nevermind, forgot to initialize Random. Didn't know that CWrite attempts to read the value before setting it (I think?)
    Just put a Random=0 before the CWrite function and it works now :dance2: thanks!

  • acayer
    Trophies
    4
    Posts
    5
    • March 8, 2022 at 10:24 PM
    • #5

    I just tried it and it works well

    Thx

Advertising from our partners

IRBCAM
Robotics Channel
Robotics Training
Advertise in robotics
Advertise in Robotics
Advertise in Robotics

Job Postings

  • Anyware Robotics is hiring!

    yzhou377 February 23, 2025 at 4:54 AM
  • How to see your Job Posting (search or recruit) here in Robot-Forum.com

    Werner Hampel November 18, 2021 at 3:44 PM
Your browser does not support videos RoboDK Software for simulation and programming

Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000

Thread Tag Cloud

  • abb
  • Backup
  • calibration
  • Communication
  • CRX
  • DCS
  • dx100
  • dx200
  • error
  • Ethernet
  • Ethernet IP
  • external axis
  • Fanuc
  • help
  • hmi
  • I/O
  • irc5
  • IRVIsion
  • karel
  • kawasaki
  • KRC2
  • KRC4
  • KRC 4
  • KRL
  • KUKA
  • motoman
  • Offset
  • PLC
  • PROFINET
  • Program
  • Programming
  • RAPID
  • robodk
  • roboguide
  • robot
  • robotstudio
  • RSI
  • safety
  • Siemens
  • simulation
  • SPEED
  • staubli
  • tcp
  • TCP/IP
  • teach pendant
  • vision
  • Welding
  • workvisual
  • yaskawa
  • YRC1000
  1. Privacy Policy
  2. Legal Notice
Powered by WoltLab Suite™
As a registered Member:
* You will see no Google advertising
* You can translate posts into your local language
* You can ask questions or help the community with your knowledge
* You can thank the authors for their help
* You can receive notifications of replies or new topics on request
* We do not sell your data - we promise

JOIN OUR GREAT ROBOTICS COMMUNITY.
Don’t have an account yet? Register yourself now and be a part of our community!
Register Yourself Lost Password
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on Google Play
Robotforum - Support and discussion community for industrial robots and cobots in the WSC-Connect App on the App Store
Download