Skip to main content
added 27 characters in body
Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13

C++11, 284284 267 bytes

Uses-17 bytes thanks to Zacharý
Uses C++ random library, output on the standard output

#include<iostream>
#include<random>
typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=0;fori=N;for(;i<N;++i;i;)a[i]=d;stda[--i]=d;std::uniform_real_distribution<z> uuniform_real_distribution<z>u(.0,d<.5?d:1-d);std::default_random_engine e;for(i=1;i<N;++i;i<N;){z c=u(e);a[i-1]+=c;a[i];a[i]+=c;a[++i]-=c;}for(i=0;i<N;++i;i;)std::cout<<a[i]<<'\n';cout<<a[--i]<<' ';}

To call, you just need to do that :

g<2>(0.0);

Where the template parameter ( here, 2 ) is N, and the actual parameter ( here, 0.0 ) is S

C++11, 284 bytes

Uses C++ random library, output on the standard output

#include<iostream>
#include<random>
typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=0;for(;i<N;++i)a[i]=d;std::uniform_real_distribution<z> u(.0,d<.5?d:1-d);std::default_random_engine e;for(i=1;i<N;++i){z c=u(e);a[i-1]+=c;a[i]-=c;}for(i=0;i<N;++i)std::cout<<a[i]<<'\n';}

To call, you just need to do that :

g<2>(0.0);

Where the template parameter ( here, 2 ) is N, and the actual parameter ( here, 0.0 ) is S

C++11, 284 267 bytes

-17 bytes thanks to Zacharý
Uses C++ random library, output on the standard output

#include<iostream>
#include<random>
typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=N;for(;i;)a[--i]=d;std::uniform_real_distribution<z>u(.0,d<.5?d:1-d);std::default_random_engine e;for(;i<N;){z c=u(e);a[i]+=c;a[++i]-=c;}for(;i;)std::cout<<a[--i]<<' ';}

To call, you just need to do that :

g<2>(0.0);

Where the template parameter ( here, 2 ) is N, and the actual parameter ( here, 0.0 ) is S

Source Link
HatsuPointerKun
  • 2.2k
  • 1
  • 8
  • 13

C++11, 284 bytes

Uses C++ random library, output on the standard output

#include<iostream>
#include<random>
typedef float z;template<int N>void g(z s){z a[N],d=s/N;int i=0;for(;i<N;++i)a[i]=d;std::uniform_real_distribution<z> u(.0,d<.5?d:1-d);std::default_random_engine e;for(i=1;i<N;++i){z c=u(e);a[i-1]+=c;a[i]-=c;}for(i=0;i<N;++i)std::cout<<a[i]<<'\n';}

To call, you just need to do that :

g<2>(0.0);

Where the template parameter ( here, 2 ) is N, and the actual parameter ( here, 0.0 ) is S