Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Zufallszahlen

Anonymous
2005-10-04
2005-10-13
  • Anonymous - 2005-10-04

    Originally created by: Tino

    Hallo!

    Kann man in CoDeSys irgendwie Zufallszahlen in einem bestimmten Bereich erzeugen?

    MfG Tino

     
  • Anonymous - 2005-10-10

    Originally created by: Frank Hailer

    Hallo Tino

    Mein Kollege Herr Wolfgang Doll hat einen einfachen Zufallszahl-Algorithmus in IEC implementiert. Der Funktionsblock RAND im angefΓΌgten Projekt Random.pro kann mit einer beliebigen 32 Bit Zahl initialisiert werden. Bei folgenden Aufrufen werden als Ergebnis positive 32 Bit DINT Zufallszahlen (im Bereich von 0 - 2147483647) erzeugt. Eine beispielhafte Anwendung zeigt Throw the dice.pro.

    MfG Frank Hailer

    Projekte.zip [12.74 KiB]

     
  • Anonymous - 2005-10-10

    Originally created by: Tino

    Vielen Dank, werd ich gleich mal ausprobieren.

    MfG Tino

     
  • Wolfgang Doll - 2005-10-13

    Hallo Tino !

    Wenn mann einmal Zufallszahlen aus einem Bereich hat, kann mit ein wenig Mathematik jeden anderen Zahlenbercih abbilden:

    Beispiel:Wir wollen REAL Zahlen im Intervall [0..1]

    Random(=>diValue);
    rValue := REAL#1.0 / (diValue + REAL#1.0);
    

    Beispiel:Wir wollen INT Zahlen im Intervall [-10..10]

    Random(=>diValue);
    iValue := DINT_TO_INT(10 - (diValue MOD 21));
    
     

Log in to post a comment.