Page 1 of 1

## 1 Replies - 166 Views - Last Post: 27 February 2018 - 01:59 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=409534&amp;s=01fdb9971f5270d6c48764c826366e24&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kulturman

Reputation: 0
• Posts: 1
• Joined: 27-February 18

Posted 27 February 2018 - 08:10 AM

Hello everybody, this is my first message on DIC and as specified in title I need your opinions about a test. Codes are in scilab and C but I thought I could post here.

1) Write a scilab programm that that simulates exponential law(distribution?) of parameter lambda

```function[Y] expo_low(lambda)
rand('uniform')
Y = -log(rand(1 , 1)) / lambda
endfunction

expo_low(0.5)

```

2.1) A scilab programm that genererates n random numbers that follow uniform distribution on [a , b]
```function[] aleatoires(n , a , B)/>
k = 1
rand('seed' , getdate('s'))
while(k <= n)
rand(1 , 1) * (b - a) + a
k = k + 1;
end
endfunction

aleatoires(10 , 1 , 2)

```

2.2) The same programm in C

```void aleatoires(int n , int a , int B)/>
{
int i = 1;
while(i <= n)
{
printf("%f" , (rand() / RAND_MAX) * (b - a) + a);
i++;
}
}

int main(void)
{
srand(time(NULL));
aleatoires(10 , 1 , 2);
return 0;
}

```

Now I see that I forgot a few things(like not casting "time" result to double or float). I just want to know if the path is the right one. Thanks

Is This A Good Question/Topic? 0

### #2 Skydiver

• Code herder

Reputation: 6063
• Posts: 20,877
• Joined: 05-May 12