humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

generate_random_text

generate_random_text($len,$type); - сгенерировать случайную строку

Функция на вход принимает параметры:

  • $len – длина текста
  • $type – тип текста (0 - латиница и кирилица, 1 - латиница , 2 - кириллица)

    После отработки функция возвращает результат своей работы в скрипт :
  • Случайный Текст – случайная строка заданной длинны и заданного типа

    Пример использования
    <?php
    // Scenario: Generate random text with different character sets (Latin, Cyrillic, or mixed)
    
    $xhe_host = "localhost:7010";
    if (!isset($path)) {
       // Path to the init.php file for connecting to the XHE API
       $path = "../../../Templates/init.php";
       // Including init.php grants access to all classes and functionality for working with the XHE API
       require($path);
    }
    
    // Start
    echo "\n<font color=blue>submitter->" . basename(__FILE__) . "</font>\n";
    
    // Step 1: Set parameters for mixed character text generation
    $count = 10;
    $minLength = 7;
    $maxLength = 12;
    $mixedChars = 0; // Latin + Cyrillic
    
    // Example 1: Generate random text 10 times with random length (7 to 12), Latin + Cyrillic
    echo "1. Get random text 10 times with random length (7 to 12), Latin + Cyrillic:\n\n";
    for ($i = 0; $i < $count; $i++) {
       // Generate random length for text
       $randomLength = WEB::$submitter->generate_random_number($minLength, $maxLength);
    
       // Get random text with mixed characters
       $randomTextMixed = WEB::$submitter->generate_random_text($randomLength, $mixedChars);
       echo $randomTextMixed . "\n";
    }
    
    // Step 2: Set parameters for Latin character text generation
    $latinChars = 1; // Latin only
    
    // Example 2: Generate random text 10 times with random length (7 to 12), Latin only
    echo "\n2. Get random text 10 times with random length (7 to 12), Latin only:\n\n";
    for ($i = 0; $i < $count; $i++) {
       // Generate random length for text
       $randomLength = WEB::$submitter->generate_random_number($minLength, $maxLength);
    
       // Get random text with Latin characters
       $randomTextLatin = WEB::$submitter->generate_random_text($randomLength, $latinChars);
       echo $randomTextLatin . "\n";
    }
    
    // Step 3: Set parameters for Cyrillic character text generation
    $cyrillicChars = 2; // Cyrillic only
    
    // Example 3: Generate random text 10 times with random length (7 to 12), Cyrillic only
    echo "\n3. Get random text 10 times with random length (7 to 12), Cyrillic only:\n\n";
    for ($i = 0; $i < $count; $i++) {
       // Generate random length for text
       $randomLength = WEB::$submitter->generate_random_number($minLength, $maxLength);
    
       // Get random text with Cyrillic characters
       $randomTextCyrillic = WEB::$submitter->generate_random_text($randomLength, $cyrillicChars);
       echo $randomTextCyrillic . "\n";
    }
    
    // End
    echo "\n";
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7013"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>submitter.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), латиница + кирилица):<br><br>")
    for i in range(0,10):
        len_text = submitter.generate_random_number(7,12)
        echo(submitter.generate_random_text(len_text,0),"<br>")
    
    # 2 
    echo("<br>2. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (латиница):<br><br>")
    for i in range(0,10):
        len_text = submitter.generate_random_number(7,12)
        echo(submitter.generate_random_text(len_text,1),"<br>")
    
    # 3 
    echo("<br>3. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (кирилица):<br><br>")
    for i in range(0,10):
        len_text = submitter.generate_random_number(7,12)
        echo(submitter.generate_random_text(len_text,2),"<br>")
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>submitter.generate_random_text</font><hr>");
    				
    			// 1 шаг
    			echo("1. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), латиница + кирилица):<br><br>");
    			for (int i=0;i<10;i++)
    			{
    				int len_text = Convert.ToInt32(submitter.generate_random_number(7,12,true));
    				echo(submitter.generate_random_text(len_text,0)+"<br>");
    			}
    			
    			// 2 шаг
    			echo("<br>2. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (латиница):<br><br>");
    			for (int i=0;i<10;i++)
    			{
    				int len_text = Convert.ToInt32(submitter.generate_random_number(7,12,true));
    				echo(submitter.generate_random_text(len_text,1)+"<br>");
    			}
    			
    			// 3 шаг
    			echo("<br>3. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (кирилица):<br><br>");
    			for (int i=0;i<10;i++)
    			{
    				int len_text = Convert.ToInt32(submitter.generate_random_number(7,12,true));
    				echo(submitter.generate_random_text(len_text,2)+"<br>");
    			}
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>submitter.generate_random_text</font><hr>");
    
    // 1 шаг
    echo("1. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), латиница + кирилица):\n");
    for (i=0;i<10;i++)
    {
    	len_text = submitter.generate_random_number(7,12);
       echo(submitter.generate_random_text(len_text,0)+"<br>");
    }
    
    // 2 шаг
    echo("<br>2. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (латиница):\n");
    for (i=0;i<10;i++)
    {
    	len_text = submitter.generate_random_number(7,12);
       echo(submitter.generate_random_text(len_text,1)+"<br>");
    }
    
    // 3 шаг
    echo("<br>3. Получить случайный текст 10 раз, случайной длинны (от 7 до 12), (кирилица):\n");
    for (i=0;i<10;i++)
    {
    	len_text = submitter.generate_random_number(7,12);
       echo(submitter.generate_random_text(len_text,2)+"<br>");
    }
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Submitter    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .