diff --git a/lib/Random/lustre_consts.c b/lib/Random/lustre_consts.c
new file mode 100644
index 0000000000000000000000000000000000000000..bc36e0d33cb2f2e0716bd6f404a2846aa0354d19
--- /dev/null
+++ b/lib/Random/lustre_consts.c
@@ -0,0 +1,4 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "lustre_consts.h"
\ No newline at end of file
diff --git a/lib/Random/lustre_consts.h b/lib/Random/lustre_consts.h
new file mode 100644
index 0000000000000000000000000000000000000000..0c80098eb11ab652e1f189c5a1abd90dbaeb0208
--- /dev/null
+++ b/lib/Random/lustre_consts.h
@@ -0,0 +1,4 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "lustre_types.h"
\ No newline at end of file
diff --git a/lib/Random/lustre_types.h b/lib/Random/lustre_types.h
new file mode 100644
index 0000000000000000000000000000000000000000..d9385f1c7473cb75e81f6a5b84b7d8a557f1d879
--- /dev/null
+++ b/lib/Random/lustre_types.h
@@ -0,0 +1,16 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#ifndef _SOC2C_PREDEF_TYPES
+#define _SOC2C_PREDEF_TYPES
+typedef int _boolean;
+typedef int _integer;
+typedef char* _string;
+typedef double _real;
+typedef double _double;
+typedef float _float;
+#define _false 0
+#define _true 1
+#endif
+// end of _SOC2C_PREDEF_TYPES
\ No newline at end of file
diff --git a/lib/Random/random.exec b/lib/Random/random.exec
new file mode 100755
index 0000000000000000000000000000000000000000..7b1d5ae64a2428c32e49038e36a4253f2c56db0d
Binary files /dev/null and b/lib/Random/random.exec differ
diff --git a/lib/Random/random.sh b/lib/Random/random.sh
new file mode 100644
index 0000000000000000000000000000000000000000..07a6da3163aef4c06ba5fc7a484bc88f5787ee5d
--- /dev/null
+++ b/lib/Random/random.sh
@@ -0,0 +1,4 @@
+if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
+$C_COMPILER -o random.exec \
+	Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c  Random/utils_random_loop.c
+
diff --git a/lib/Random/random.sh~ b/lib/Random/random.sh~
new file mode 100644
index 0000000000000000000000000000000000000000..07a6da3163aef4c06ba5fc7a484bc88f5787ee5d
--- /dev/null
+++ b/lib/Random/random.sh~
@@ -0,0 +1,4 @@
+if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
+$C_COMPILER -o random.exec \
+	Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c  Random/utils_random_loop.c
+
diff --git a/lib/Random/utils_random.c b/lib/Random/utils_random.c
new file mode 100644
index 0000000000000000000000000000000000000000..5d2b57e70ad2733ae3f6daa30db4a437d36b78d2
--- /dev/null
+++ b/lib/Random/utils_random.c
@@ -0,0 +1,13 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "utils_random.h"
+//// Defining step functions
+// Step function(s) for utils_c_rand_ctx
+// Step function(s) for utils_random_ctx
+void utils_random_step(_integer x,_integer *res){
+
+  utils_c_rand_step(x,res); 
+
+} // End of utils_random_step
+
diff --git a/lib/Random/utils_random.h b/lib/Random/utils_random.h
new file mode 100644
index 0000000000000000000000000000000000000000..9109348389598202f3cd0234deca4d7baf078c80
--- /dev/null
+++ b/lib/Random/utils_random.h
@@ -0,0 +1,24 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "lustre_consts.h"
+
+// User typedef 
+#ifndef _utils_random_TYPES
+#define _utils_random_TYPES
+// Memoryless soc ctx typedef 
+// Memoryfull soc ctx typedef 
+#endif // end of  _utils_random_TYPES
+
+#ifndef _utils_random_H_FILE
+#include "utils_random_ext.h"
+#define _utils_random_H_FILE
+#endif // _utils_random_H_FILE
+
+void utils_random_step(_integer ,_integer *);
+
+/////////////////////////////////////////////////
diff --git a/lib/Random/utils_random_ext.c b/lib/Random/utils_random_ext.c
new file mode 100644
index 0000000000000000000000000000000000000000..83e091f80507ada189b4e143de7abc7acf7874c2
--- /dev/null
+++ b/lib/Random/utils_random_ext.c
@@ -0,0 +1,6 @@
+#include "utils_random.h"
+#include <assert.h>
+void utils_c_rand_step(_integer x,_integer *res){
+  assert (0 < x );
+  *res = (rand() % x);
+}
diff --git a/lib/Random/utils_random_ext.c~ b/lib/Random/utils_random_ext.c~
new file mode 100644
index 0000000000000000000000000000000000000000..482555db736c1ad6869ab927b57ae4964e507f72
--- /dev/null
+++ b/lib/Random/utils_random_ext.c~
@@ -0,0 +1,5 @@
+#include "utils_random.h"
+void utils_c_rand_step(_integer x,_integer *res){
+  assert (0 < x );
+  *res = (rand() % x);
+}
diff --git a/lib/Random/utils_random_ext.h b/lib/Random/utils_random_ext.h
new file mode 100644
index 0000000000000000000000000000000000000000..80c5463d74ddc6907b5db2b73555db161c442646
--- /dev/null
+++ b/lib/Random/utils_random_ext.h
@@ -0,0 +1 @@
+void utils_c_rand_step(_integer ,_integer *);
diff --git a/lib/Random/utils_random_loop.c b/lib/Random/utils_random_loop.c
new file mode 100644
index 0000000000000000000000000000000000000000..4aac425fc3f9c7e391cf2c73b88a0ba6d9fee24c
--- /dev/null
+++ b/lib/Random/utils_random_loop.c
@@ -0,0 +1,151 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "utils_random.h" 
+/* Print a promt ? ************************/
+static int ISATTY;
+/* MACROS DEFINITIONS ****************/
+#ifndef TT
+#define TT "1"
+#endif
+#ifndef FF
+#define FF "0"
+#endif
+#ifndef BB
+#define BB "bottom"
+#endif
+#ifdef CKCHECK
+/* set this macro for testing output clocks */
+#endif
+
+void _read_pragma(char b[]) {
+
+   if (!strcmp(b,"#quit")) exit(0);
+   if (!strcmp(b,"#q")) exit(0);
+}
+char* _get_string(char* n){
+   static char b[10] = "dummy";
+   return b;
+}
+/* Standard Input procedures **************/
+_boolean _get_bool(char* n){
+   char b[512];
+   char c;
+   _boolean r = 0;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if((s != 1)||(r == -1)) printf("\a");
+         // printf("%s (1,t,T/0,f,F) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      r = -1;
+      c=b[0];
+      if(c == 'q') exit(0);
+      if(c == '#') _read_pragma(b);
+      if((c == '0') || (c == 'f') || (c == 'F')) r = 0;
+      if((c == '1') || (c == 't') || (c == 'T')) r = 1;
+   } while((s != 1) || (r == -1));
+   return r;
+}
+_integer _get_int(char* n){
+   char b[512];
+   _integer r;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if(s != 1) printf("\a");
+         //printf("%s (integer) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      if(*b == 'q') exit(0);
+      if(*b == '#') {
+         _read_pragma(b);
+      } else {
+        s = sscanf(b, "%d", &r);
+      }
+   } while(s != 1);
+   return r;
+}
+#define REALFORMAT ((sizeof(_real)==8)?"%lf":"%f")
+_real _get_real(char* n){
+   char b[512];
+   _real r;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if(s != 1) printf("\a");
+         //printf("%s (real) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      if(*b == 'q') exit(0);
+      if(*b == '#') {
+         _read_pragma(b);
+      } else {
+         s = sscanf(b, REALFORMAT, &r);
+      }
+   } while(s != 1);
+   return r;
+}
+/* Standard Output procedures **************/
+void _put_bottom(char* n){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", BB);
+   if(ISATTY) printf("\n");
+}
+void _put_bool(char* n, _boolean _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", (_V)? TT : FF);
+   if(ISATTY) printf("\n");
+}
+void _put_int(char* n, _integer _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%d ", _V);
+   if(ISATTY) printf("\n");
+}
+void _put_real(char* n, _real _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%f ", _V);
+   if(ISATTY) printf("\n");
+}
+void _put_string(char* n, char* _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", _V);
+   if(ISATTY) printf("\n");
+}
+
+/* Output procedures **********************/
+#ifdef CKCHECK
+void %s_BOT_n(void* cdata){
+   _put_bottom("n");
+}
+#endif
+
+/* Main procedure *************************/
+int main(){
+  int _s = 0;
+  _integer x;
+  _integer res;
+  
+  printf("#inputs \"x\":int\n");
+  printf("#outputs \"res\":int\n");
+
+  /* Main loop */
+  ISATTY = isatty(0);
+  while(1){
+    if (ISATTY) printf("#step %d \n", _s+1);
+    else if(_s) printf("\n");
+    fflush(stdout);
+    ++_s;
+    x = _get_int("x");
+    utils_random_step(x,&res);
+    // printf("%d #outs %d\n",x,res);
+    printf("%d\n",res);
+  }
+  return 1;
+   
+}
diff --git a/lib/sas.lus b/lib/sas.lus
index 2451a5be393b4d07114e785809f6fa047d85aec1..ffa29ac83fe3b7c663d92d9f5c496e8ce477ad20 100644
--- a/lib/sas.lus
+++ b/lib/sas.lus
@@ -37,6 +37,10 @@ let
       and (silent<<an,pn>>(enab) or boolred<<1,pn,pn>>(map<<boolany<<an>>, pn>>(acti)));
 tel;
 
+(*function distributed<<const an:int; const pn:int>>(enab : bool^an^pn)
+returns (acti : bool^an^pn);
+var
+  nb_enab,rng:int;*)
 -- Exactly one node is activated.
 node daemon_is_central<<const an:int; const pn:int>>(acti, enab : bool^an^pn)
 returns (y : bool);
@@ -46,6 +50,31 @@ let
 
 tel;
 
+function make_activ_tab<<const an:int>>(ain:int; elem:bool^an)
+returns(aout:int; res:bool^an);
+var
+  elem_is_true:bool;
+let
+  elem_is_true = boolany<<an>>(elem);
+  res= if elem_is_true and (ain=0) then elem else false^an;
+  aout = if elem_is_true then ain-1 else ain;
+tel;
+
+function if_true_add_1<<const an:int>>(ain: int; elem: bool^an)
+returns(aout : int);
+let
+  aout= if boolany<<an>>(elem) then ain+1 else ain; 
+tel;
+
+unsafe function central<<const an:int; const pn:int>>(enab : bool^an^pn)
+returns (acti : bool^an^pn);
+var
+  nb_enab,rng,temp:int;
+let
+  nb_enab = red<<if_true_add_1<<an>>,pn>>(0,enab);
+  rng = random(nb_enab);
+  temp,acti = fillred<<make_activ_tab<<an>>,pn>>(rng,enab);
+tel; 
 
 -- No two neighboring nodes are active at once.
 node daemon_is_locally_central<<const an:int; const pn:int>>(
diff --git a/lib/use_random.lus b/lib/use_random.lus
new file mode 100644
index 0000000000000000000000000000000000000000..975f366903e39f2139e2d7833d4577230abde205
--- /dev/null
+++ b/lib/use_random.lus
@@ -0,0 +1,2 @@
+--Make a random function for Lustre by using C function:
+unsafe extern function c_rand(x:int) returns (res:int);
\ No newline at end of file
diff --git a/lib/utils.lus b/lib/utils.lus
index 4d16cbb3edad3c9ae8699c2495b3fafa23d69b5a..1568d3a716a866ec3bc0a29a2781eb8e41bd8108 100644
--- a/lib/utils.lus
+++ b/lib/utils.lus
@@ -1,3 +1,11 @@
+include "use_random.lus"
+
+--Random (unsafe extern function):
+unsafe function random(x:int) returns (res:int);
+let
+  res = c_rand(x);
+tel
+
 -- Generates an array of indexes: [0, 1, ..., N-1]
 function range<<const N:int>>(_ : bool) returns (r : int^N);
 let
@@ -80,4 +88,4 @@ function weight (e:neigh)
 returns(res : int);
 let
   res = e.weight;
-tel;
+tel;
\ No newline at end of file