How to Format a URL with a variable for http_request.post

I have an Lambda formatting issue I cant seem to solve and looking for any hints. I want to post a URL with a random number in it to a http API endpoint ( a remote WLED ESP8266 ). Its not connected to Home Assistant and its via a proxy so just sending a URL works fine.

     - http_request.post:
          url: !lambda |-
            set random_length = (rand() % 136);
            id(mqtt_client).publish("/light/esp32-01/random_length",esphome::to_string(random_length));
            char buf[256];
            buf = "http://10.0.0.59/win&T=1&A=128&FX=" + esphome::to_string(random_length) + "&SX=255&R=255&G=255&B=255";
            return ((std::string) buf).c_str();

I have tried a few versions of the above, but constantly getting an error. The current one is above, but causes this error

Compiling .pioenvs/esp32-01/src/main.cpp.o
esp32-01.yaml: In lambda function:
esp32-01.yaml:375:7: error: 'set' was not declared in this scope
esp32-01.yaml:375:7: note: suggested alternative:
In file included from /root/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/set:61,
                 from src/esphome/components/light/light_call.h:5,
                 from src/esphome/components/light/light_state.h:7,
                 from src/esphome/core/controller.h:11,
                 from src/esphome/components/api/api_server.h:4,
                 from src/esphome/components/api/api_connection.h:6,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/root/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/include/c++/8.4.0/bits/stl_set.h:94:11: note:   'std::set'
     class set
           ^~~
esp32-01.yaml:376:79: error: 'random_length' was not declared in this scope
esp32-01.yaml:376:79: note: suggested alternative: 'random_sensor'
*** [.pioenvs/esp32-01/src/main.cpp.o] Error 1

Interested in a better way to send the URL dont mind how / why / where…

The original suggestion was to return the URL like this.

            return ((std::string) "http://10.0.0.59/win&T=1&A=128&FX=" + id(random_sensor).state + "&SX=255&R=255&G=255&B=255");

The random_sensor was created like this

  - platform: template
    name: "Random Numbers"
    id: random_sensor
    lambda: |-
      return rand() % 100;
    update_interval: 60s

But alas this returned a much larger error started from this

Compiling .pioenvs/esp32-01/src/main.cpp.o
esp32-01.yaml: In lambda function:
esp32-01.yaml:375:66: error: no match for 'operator+' (operand types are 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} and 'float')
In file included from src/esphome/core/entity_base.h:5,
                 from src/esphome/components/light/light_state.h:4,
                 from src/esphome/core/controller.h:11,
                 from src/esphome/components/api/api_server.h:4,
                 from src/esphome/components/api/api_connection.h:6,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
src/esphome/core/string_ref.h:118:20: note: candidate: 'std::__cxx11::string esphome::operator+(const char*, const esphome::StringRef&)'
 inline std::string operator+(const char *lhs, const StringRef &rhs) {

Thanks
Martin

PS. I was able to fix this with a line like this

          url: !lambda |-
            return ((std::string) "http://10.0.0.59/win&T=1&A=128&FX=" + esphome::to_string(id(random_sensor).state) + "&SX=255&R=255&G=255&B=255");~