# RANDOM is broken in C11.1.13815

**URL:** <https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938>\
**Category:** tips\
**Tags:** bugs, c11.1\
**Created:** [January 26, 2024, 10:11am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938 "2024-01-26T10:11:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [January 26, 2024, 10:11am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/1 "2024-01-26T10:11:31Z")

</div>

Simple code that produces a sequence of random numbers:

```auto
  PROGRAM

  MAP
    INCLUDE('printf.inc'), ONCE
  END

i LONG, AUTO
v LONG, AUTO

  CODE
  LOOP i=1 TO 10
    v = RANDOM(0, 360)
    printd('random[%i]=%i', i, v)
  END

```

In C11.1.13815 it always produces the same sequence of numbers, in my case it is

```auto
random[1]=312
random[2]=62
random[3]=234
random[4]=214
random[5]=15
random[6]=26
random[7]=349
random[8]=212
random[9]=214
random[10]=241

```

Checked in C8 and C10 - the sequence is different every time.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 26, 2024, 2:41pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/2 "2024-01-26T14:41:36Z")

</div>

Hi Mike - I wonder if srand or randomize would help.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 26, 2024, 3:01pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/3 "2024-01-26T15:01:50Z")

</div>

It does seem to work, if a sucky workaround is OK.

```auto
  MAP
    MODULE('')
      SRand(ushort),name('_srand')
    END
  END

```

```auto
    SRand(CLOCK()+i)
    v = RANDOM(0, 360)

```

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [January 26, 2024, 3:32pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/4 "2024-01-26T15:32:39Z")

</div>

Interesting, Mike.  
Have you sent that into SV support? Hopefully, that is something they would jump on right away to fix.  
I tested with 11 13505 and it does not happen with that version..

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 26, 2024, 3:40pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/5 "2024-01-26T15:40:38Z")

</div>

It does happen in .13815

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [January 27, 2024, 8:30am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/6 "2024-01-27T08:30:11Z")

</div>

There is definitely no such problem in Clarion 11.1.13845 …

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [January 27, 2024, 9:44am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/7 "2024-01-27T09:44:11Z")

</div>

Thanks, tt’s a good news!

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [January 28, 2024, 4:32am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/8 "2024-01-28T04:32:35Z")

</div>

An interesting aside;

StringTheory uses Random in the generation of Guids. Since random seeds from the time this worked fine.

Until one enterprising programmer had a process that started multiple child exes in the same centisecond.

So now StringTheory initialises the random number using a combination of the time, and process id. So if you run the above test after calling st.random, itll be fine even on the noted build.

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [January 28, 2024, 7:47am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/9 "2024-01-28T07:47:46Z")

</div>

> [@Bruce](#):
>
> StringTheory uses Random in the generation of Guids

Very strange things. There is a CoCreateGuid() method for GUID in WinAPI. Why don’t we know the names of those who do all this?

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [January 28, 2024, 11:08am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/10 "2024-01-28T11:08:54Z")

</div>

Hi Genricke -  
I’m not sure I understand what you are asking? Perhaps “why doesn’t StringTheory use CoCreateGuid?”  
Or something else?

Bruce

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [January 28, 2024, 2:59pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/11 "2024-01-28T14:59:48Z")

</div>

> [@Bruce](#):
>
> why doesn’t StringTheory use CoCreateGuid?

Yes! Why String Theory is used to create a Random() GUID.

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [January 29, 2024, 4:56am UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/12 "2024-01-29T04:56:34Z")

</div>

You might find this reference helpful in understanding this explanation; [Universally unique identifier - Wikipedia](https://en.m.wikipedia.org/wiki/Universally_unique_identifier)

The short version is that all uuids are 128 bits long. The ones you are familiar with on MS platforms are typically displayed as hex-encoded (32 nibbles plus some hyphens).

While stringtheory has a method for generating version 4 uuids, for general use it prefers to use a ASCII value in 16 chars, which represents around 80 bits of entropy.

This is sufficient for the main use case (unique per table) and can be generated on any platform, in any language. Its also visible and editable in readers (like topscan) without encoding or decoding. It also does not need encoding in text formats like CSV, JSON or XML. It can even be used (and generated) in Excel and so on.

It’s fundamentally suitable for two use cases.

A) replacing auto-numbering (client or server side) and so bypassing all the problems that auto numbering has.

B) data distribution - allowing data to exist in multiple databases (including sql, isam, and text) at the same time.

C) compatible with all platforms and all languages. (Although generating version 4 uuids is not hard, it can be tricky because of the embedded version number.)

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [May 26, 2025, 5:28pm UTC](https://clarionhub.com/t/random-is-broken-in-c11-1-13815/6938/13 "2025-05-26T17:28:56Z")

</div>

I am seeing the above constant same value issue with `RANDOM` on 11..1.13855
