����������˵����������ԭ�⡰��Ⱥ�Ĺ��ܣ�ԭ�����������Ƶģ�������ʱͨѶ���������Ű��������Ż��ȡ�
1.png (10.38 KB, ���ش���: 3277)
���ظ��� ���浽����
1 ��ǰ �ϴ�
2.png (7.62 KB, ���ش���: 3276)
cover-opti.png (10.56 KB, ���ش���: 3205)
3.png (17.64 KB, ���ش���: 3313)
4.png (24.71 KB, ���ش���: 3232)
5.png (23.79 KB, ���ش���: 3146)
{�����룬�û��б�[�û�A(ID�����ơ�ͷ��)]}
6.png (18.57 KB, ���ش���: 3252)
7.png (44 KB, ���ش���: 3285)
8.png (13.1 KB, ���ش���: 3256)
9.png (17.86 KB, ���ش���: 3402)
10.png (16.97 KB, ���ش���: 3387)
11.png (16.59 KB, ���ش���: 3206)
import ( "fmt" "math" "math/rand" "strconv" ) type RedPack struct { SurplusAmount float64 // ʣ������ SurplusTotal int // ����ʣ������ } // ȡ��λС�� func remainTwoDecimal(num float64) float64 { numStr := strconv.FormatFloat(num, 'f', 2, 64) num, _ = strconv.ParseFloat(numStr, 64) return num } // ��ȡ���������ĺ��� func getRandomRedPack(rp *RedPack) float64 { if rp.SurplusTotal <= 0 { // �ú����Ѿ��������� return 0 } if rp.SurplusTotal == 1 { return remainTwoDecimal(rp.SurplusAmount + 0.01) } // ����ȡ�� avgAmount := math.Floor(100*(rp.SurplusAmount/float64(rp.SurplusTotal))) / float64(100) avgAmount = remainTwoDecimal(avgAmount) // �������������� rand.NewSource(time.Now().UnixNano()) var max float64 if avgAmount > 0 { max = 2*avgAmount - 0.01 } else { max = 0 } money := remainTwoDecimal(rand.Float64()*(max) + 0.01) rp.SurplusTotal -= 1 rp.SurplusAmount = remainTwoDecimal(rp.SurplusAmount + 0.01 - money) return money } func main() { rp := &RedPack{ SurplusAmount: 0.06, SurplusTotal: 5, } // ÿ�������ȱ��� 0.01 ������ rp.SurplusAmount -= 0.01 * float64(rp.SurplusTotal) total := rp.SurplusTotal for i := 0; i < total; i++ { fmt.Println(getRandomRedPack(rp)) } }
0.01��0.01��0.01��0.01��0.02
��Դ����ʱͨѶ�� - ��ʱͨѶ������������
��������Դ�ƶ��˼�ʱͨѶ���ܡ�
�������� / ���� / ָ�� / ����
������Web�˼�ʱͨѶ���ܡ�
��ϸ���� / ����Դ�� / �ֲ��̳�
�ƶ���ʵʱ����Ƶ���ܡ�
��ϸ���� / ���ܲ��� / ��װ����
����MobileIMSDK���ƶ�IMϵͳ��
��ϸ���� / ��Ʒ��ͼ / ��װ����
һ�ײ�Ʒ��Web��IMϵͳ��
��ϸ���� / ��Ʒ��ͼ / ��ʾ��Ƶ
һ�״�Ѫ����NEXT��Ʒ��IMϵͳ��
��ϸ���� / ��Ʒ��ͼ / ��װ
��������������100����
������ְ��2�����ϵĺϸ���ʽ����
Ϊ��������ͻ�����Ŀ����ߡ������ȡ�
Copyright © 2014-2024 ��ʱͨѶ�� - ��ʱͨѶ���������� / �汾 V4.4
��������ʱ����Ϣ�Ƽ�����˾ (��ICP��16005070��-1��
Processed in 0.164052 second(s), 43 queries , Gzip On.