A Discrete-Event Network Simulator
API
sample-rng-plot.py
Go to the documentation of this file.
1# -*- Mode:Python; -*-
2# /*
3# * This program is free software; you can redistribute it and/or modify
4# * it under the terms of the GNU General Public License version 2 as
5# * published by the Free Software Foundation
6# *
7# * This program is distributed in the hope that it will be useful,
8# * but WITHOUT ANY WARRANTY; without even the implied warranty of
9# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# * GNU General Public License for more details.
11# *
12# * You should have received a copy of the GNU General Public License
13# * along with this program; if not, write to the Free Software
14# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15# */
16
17
24
25
26import numpy as np
27import matplotlib.pyplot as plt
28import ns.core
29
30# mu, var = 100, 225
31rng = ns.core.NormalRandomVariable()
32rng.SetAttribute("Mean", ns.core.DoubleValue(100.0))
33rng.SetAttribute("Variance", ns.core.DoubleValue(225.0))
34x = [rng.GetValue() for t in range(10000)]
35
36# the histogram of the data
37n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
38
39plt.title('ns-3 histogram')
40plt.text(60, .025, r'$\mu=100,\ \sigma=15$')
41plt.axis([40, 160, 0, 0.03])
42plt.grid(True)
43plt.show()